SaaS uptime monitoring services charge absurd monthly premiums for what essentially boils down to HTTP GET requests and SSL certificate expiration checks. When running dozens of microservices or client sites, paying $50 per month per service monitor quickly becomes an unnecessary overhead.
The Architectural Blueprint
A resilient watchdog does not require a heavy distributed tracing engine. It needs a lean polling worker, exponential backoff logic on failures, certificate expiration checking, and an isolated static status generator.
Building the Core Python Monitoring Engine
Below is a resilient worker script designed to validate target endpoints, measure response latency, and inspect TLS certificates in a single pass.
import datetime
import socket
import ssl
import requests
def check_target(url: str, hostname: str, port: int = 443, timeout: int = 5) -> dict:
results = {"url": url, "healthy": False, "latency_ms": 0, "ssl_days_remaining": 0}
# 1. HTTP Status & Latency Check
try:
response = requests.get(url, timeout=timeout)
results["healthy"] = response.status_code == 200
results["latency_ms"] = round(response.elapsed.total_seconds() * 1000, 2)
except requests.RequestException as e:
return {**results, "error": f"HTTP Failure: {str(e)}"}
# 2. SSL Certificate Expiry Check
context = ssl.create_default_context()
with socket.create_connection((hostname, port), timeout=timeout) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
cert = ssock.getpeercert()
expiry_raw = cert["notAfter"]
expiry_date = datetime.datetime.strptime(expiry_raw, "%b %d %H:%M:%S %Y %Z")
results["ssl_days_remaining"] = (expiry_date - datetime.datetime.utcnow()).days
return results
if __name__ == "__main__":
metrics = check_target("https://api.py-forge.com/health", "api.py-forge.com")
print(metrics)This script can be executed on a periodic schedule using systemd timers or lightweight container orchestration. If a check fails twice sequentially, the watchdog triggers a Webhook payload to Slack, Discord, or PagerDuty.
Static Status Page Rendering
Instead of hosting a dynamic database-driven dashboard—which can crash during cloud outages—dump state results to a static JSON payload and push it to an S3 bucket or GitHub Pages for rock-solid availability.