Cheap Python Uptime Dashboard: Custom Metrics for Internal Admin Status
Short answer: a cheap Python uptime dashboard should use custom metrics to detect missing marketplace results, not treat a green process as proof that scheduled work happened. Record one durable row for each run and render the same facts on the internal admin status page. During a rollback, keep the writer schema backward-compatible so old and new workers can report liveness at the same time.…
To create a cheap Python uptime dashboard that accurately monitors internal admin status, focus on using custom metrics to detect missing marketplace results rather than relying on a green process as proof of successful scheduled work. Maintain a durable record for each run, displaying the same information on the internal admin status page. Ensure backward compatibility during rollbacks by allowing both old and new workers to report liveness simultaneously. This approach carries more weight than dashboard aesthetics.
A simple green /health response confirms that a process can respond, but it doesn't verify that the expected tasks like fetching, parsing, accepting, and publishing data were completed. Instead, prioritize the age of the last successful run producing the expected result, considering whether the current run is active. Custom metrics should include key elements such as scheduled timestamp, start and finish timestamps, outcome, input count, accepted count, rejected count, and reason code.
Define a clear contract before implementing the dashboard to prevent ambiguity in interpreting zero values.
Counters like successful runs should reflect the differences between a quiet supplier, a broken upstream file, accidental filters, or parsers that accepted nothing. Zero can be misleading in this context. Instead, use well-defined reason codes such as completed, empty_expected, empty_unexpected, fetch_failed, parse_failed, and publish_failed to capture critical aspects of each run. Limit the scope of reason codes to prevent confusion with raw exception messages.
Leverage Prometheus's guidance on high-cardinality labels by storing supplier IDs, filenames, trace IDs, and exception text in logs or run records instead of metric labels. Alert when no qualifying run finishes within the scheduled interval plus a grace period. Treat empty_expected runs as qualifying only when an explicit business rule predicts an empty feed.
Suppress alerts for missing results while a run is still active and within its maximum duration, but raise a separate alert for stuck runs afterward. This distinction helps differentiate between lateness and failure.
Implement the underlying data flow before creating visualizations. The scheduler generates run records, workers update these records at various phase boundaries, a metrics collector transforms completed records into low-cardinality time series, and an internal page reads from a summarized endpoint. Alerts query the metrics backend, and the ledger serves as an audit trail when data is aggregated or the process restarts.
Start with a simple in-memory version of the core components, modeling the contract and alert decision logic without directly coupling the worker to a dashboard library. For production use, replace the RunStore with a transactional database and emit measurements through the existing metrics client used by the service.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to