A health checker package to report using MQTT
Project description
healthcheck-reporter
Lightweight health reporter that periodically probes database TCP connectivity and publishes a JSON report to MQTT.
Installation
pip install healthcheck-reporter
Usage
from healthcheck_reporter import Reporter, ReporterConfig
config = ReporterConfig(
database_host="db.example.local",
database_port=5432,
database_name="appdb",
database_password="secret",
database_user="app",
mqtt_host="mqtt.example.local",
mqtt_port=1883,
mqtt_client_id="service-A-health",
mqtt_topic="services/health",
mqtt_user=None, # or "user"
mqtt_password=None, # or "password"
)
reporter = Reporter(
config,
interval_seconds=30.0, # configurable, non-blocking
debug_mode=False, # set to True for testing status transitions
)
reporter.start()
# ... your service runs ...
# On shutdown
reporter.stop()
Published payload
{
"database_status": "ok",
"mqtt_client_id": "service-A-health",
"timestamp": "2025-01-01T00:00:00+00:00",
"db_error_count": 0,
"mqtt_error_count": 0,
"db_failure_rate": 0.0,
"mqtt_failure_rate": 0.0,
"overall_status": "operational"
}
Notes
- A real PostgreSQL connection is attempted first (psycopg2 is required); otherwise it falls back to a TCP probe if the driver is unavailable in the environment.
- MQTT publish uses QoS 1 and reconnects if needed.
start()runs a background thread (non-blocking). Usestop()on shutdown.
Metrics
- Cumulative counters since process start:
db_error_count: number of failed DB probesmqtt_error_count: number of failed MQTT publishes
- Failure rates (percentages):
db_failure_rate: failed DB probes / total DB probe attemptsmqtt_failure_rate: failed MQTT publishes / total MQTT publish attempts
- Derived overall status:
operational: DB is currently reachable and failure rates < 20%degraded: failure rate of DB or MQTT >= 20%unavailable: current DB probe failed
- Debug mode (
debug_mode=True): alternates between "degraded" and "unavailable" every 5 seconds for testing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file healthcheck_reporter-0.1.4.tar.gz.
File metadata
- Download URL: healthcheck_reporter-0.1.4.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d57ae613e819c967062e34e7570d19f0e9abcc0330f54cb277292ee00808b61
|
|
| MD5 |
e885a8ef502a2b930ac4765103f3ead7
|
|
| BLAKE2b-256 |
5cdcb8015e0f87aa61a5073e3dac7ed5c8712c3067aa06afb9fabf422cd5926d
|
File details
Details for the file healthcheck_reporter-0.1.4-py3-none-any.whl.
File metadata
- Download URL: healthcheck_reporter-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b89d61c59d70716e3e056d1eff7da7e70f4d28f19680609c483b95f7a4ccc75
|
|
| MD5 |
e08f0aaab1120403dd9bd3553e1149f5
|
|
| BLAKE2b-256 |
0a35655c21caf7c3b6d4ae536dde782c22207c933cc205f33f60c9528e6f094f
|