Monitoring
Prometheus metrics collection and HTTP server for /metrics.
The redup_servicekit.monitoring module contains:
redup_servicekit.monitoring.TaskStatus— enum for task outcome (OK, FATAL, etc.)redup_servicekit.monitoring.ErrorParser— map exceptions to error types and health statusredup_servicekit.monitoring.StatusParser— success/failure label for statsredup_servicekit.monitoring.MonitorStorage— async storage for stats; registry updated on /metricsredup_servicekit.monitoring.MetricServer— HTTP server that serves /metricsredup_servicekit.monitoring.MonitorServer— singleton entry point; runs MetricServer, forwards to storage
- class TaskStatus(*values)[source]
Bases:
EnumStatus of a task for health reporting.
Used when reporting task outcome: OK, FATAL, CONNECTION_ERROR, OTHER_EXCEPTION, INTERNAL, UNKNOWN. Config maps error types to these and to an unhealthy threshold.
- OK = 1
- FATAL = 2
- CONNECTION_ERROR = 3
- OTHER_EXCEPTION = -1
- INTERNAL = 4
- UNKNOWN = 5
- class ErrorParser[source]
Bases:
objectMaps exception tracebacks to error type strings and sets task status for health.
- class StatusParser[source]
Bases:
objectReturns
failureorsuccesslabel for processed-request stats.
- class MonitorStorage[source]
Bases:
objectAsync storage for monitoring state.
Holds stats and task status. The Prometheus registry is updated only when
refresh_registry_for_metrics()is called (e.g. on each /metrics request). Methods: inc_stats, set_stats, set_task_status, append_stats, add_key_value, del_key_value, get_stats, get_statuses.
- class MetricServer(registry=prometheus_client.registry.REGISTRY, disable_compression=False, storage=None)[source]
Bases:
objectHTTP server that serves /metrics.
On each /metrics request refreshes the Prometheus registry from the provided storage, then exports. Use
run_in_thread()to start in a daemon thread on a given port.- Parameters:
registry – Prometheus registry to export. Default
REGISTRY.disable_compression – If True, disable response compression.
storage – Optional
MonitorStorage; if set, registry is refreshed from it on each request.
- __init__(registry=prometheus_client.registry.REGISTRY, disable_compression=False, storage=None)[source]
- class MonitorServer[source]
Bases:
objectSingleton entry point for monitoring.
Holds
MonitorStorage, runsMetricServerin a thread, forwards all stats/status calls to storage. Callrun()with server config (port, errors, service info) to start the metrics HTTP server. Useget_instance()to get the singleton from decorators or app code.Example:
>>> server = MonitorServer() >>> server.run(server_config={"port": 9999, "errors": {...}}, max_workers=4) >>> await server.inc_stats("request___method__MyMethod")