Monitoring critical web services and APIs shouldn't require deploying a heavy observability stack. When testing distributed endpoints or tracking response times across multiple environments, a lightweight, dependency-minimal CLI utility gives you immediate visibility into uptime and latency SLAs.
I built an open-source HTTP Endpoint Health & Latency Monitor in Python to automate endpoint health checks using a declarative YAML configuration file.
Core Capabilities
- Declarative YAML Configuration: Define target URLs, expected HTTP status codes, and custom latency thresholds in a clean, human-readable
config.yamlfile. - Sub-Millisecond Latency Measurement: Tracks round-trip response times using
time.perf_counter()to flag endpoints that return200 OKbut violate response-time SLAs. - Structured Terminal & Log Output: Outputs clear pass/warn/fail status summaries suitable for cron jobs, CI/CD smoke tests, or lightweight server monitoring.
Example Configuration (config.yaml)
endpoints: - name: "Primary API Gateway" url: "[https://api.example.com/health](https://api.example.com/health)" expected_status: 200 max_latency_ms: 500 - name: "Authentication Service" url: "[https://auth.example.com/status](https://auth.example.com/status)" expected_status: 200 max_latency_ms: 350 Core Health Check Implementation
Using Python's requests library alongside PyYAML, the core validation loop evaluates both HTTP status integrity and latency thresholds in a single pass:
import time import requests import yaml def check_endpoint(endpoint: dict) -> dict: url = endpoint["url"] expected_status = endpoint.get("expected_status", 200) max_latency = endpoint.get("max_latency_ms", 500) start = time.perf_counter() try: response = requests.get(url, timeout=5) latency_ms = round((time.perf_counter() - start) * 1000, 2) status_ok = response.status_code == expected_status latency_ok = latency_ms <= max_latency return { "name": endpoint["name"], "status": response.status_code, "latency_ms": latency_ms, "healthy": status_ok and latency_ok, } except requests.RequestException as exc: return { "name": endpoint["name"], "status": "ERROR", "latency_ms": None, "healthy": False, "error": str(exc), } if __name__ == "__main__": with open("config.yaml", "r", encoding="utf-8") as f: config = yaml.safe_load(f) for target in config.get("endpoints", []): result = check_endpoint(target) state = "PASS" if result["healthy"] else "FAIL" print(f"[{state}] {result['name']} -> Status: {result['status']} | Latency: {result['latency_ms']}ms") Source Code & Links
- GitHub Profile & Repositories: github.com/victor-koncurat
- Full Bio & Projects: victorkoncurat.wordpress.com/about
- Technical Writing on Substack: victorkoncurat.substack.com