feat: add typed qBittorrent scheduled polling
This commit is contained in:
@@ -77,6 +77,28 @@ MAIL_QUEUE_SIZE = Counter(
|
||||
["status"],
|
||||
)
|
||||
|
||||
SCHEDULED_ACTIONS_TOTAL = Counter(
|
||||
"manage_scheduled_actions_total",
|
||||
"Total typed scheduled action attempts",
|
||||
["service_id", "action", "status"],
|
||||
)
|
||||
SCHEDULED_ACTION_DURATION = Histogram(
|
||||
"manage_scheduled_action_duration_seconds",
|
||||
"Typed scheduled action duration",
|
||||
["action"],
|
||||
buckets=(0.01, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0),
|
||||
)
|
||||
SCHEDULED_ACTION_LAST_SUCCESS = Gauge(
|
||||
"manage_scheduled_action_last_success_timestamp",
|
||||
"Unix timestamp of the last successful typed scheduled action",
|
||||
["service_id", "action"],
|
||||
)
|
||||
SCHEDULED_ACTION_FAILURES = Gauge(
|
||||
"manage_scheduled_action_consecutive_failures",
|
||||
"Current consecutive failure count for a typed scheduled action",
|
||||
["service_id", "action"],
|
||||
)
|
||||
|
||||
|
||||
def set_current_request_id(request_id: str | None) -> None:
|
||||
"""Set the context-local request id."""
|
||||
@@ -147,6 +169,25 @@ def record_mail_queue(status: str) -> None:
|
||||
MAIL_QUEUE_SIZE.labels(status=status).inc()
|
||||
|
||||
|
||||
def record_scheduled_action(
|
||||
service_id: str,
|
||||
action: str,
|
||||
status: str,
|
||||
duration_seconds: float | None = None,
|
||||
success: bool = False,
|
||||
consecutive_failures: int = 0,
|
||||
) -> None:
|
||||
"""Record secret-safe metrics for a typed scheduled action."""
|
||||
safe_service = service_id or "unknown"
|
||||
safe_action = action or "unknown"
|
||||
SCHEDULED_ACTIONS_TOTAL.labels(service_id=safe_service, action=safe_action, status=status).inc()
|
||||
SCHEDULED_ACTION_FAILURES.labels(service_id=safe_service, action=safe_action).set(consecutive_failures)
|
||||
if duration_seconds is not None:
|
||||
SCHEDULED_ACTION_DURATION.labels(action=safe_action).observe(duration_seconds)
|
||||
if success:
|
||||
SCHEDULED_ACTION_LAST_SUCCESS.labels(service_id=safe_service, action=safe_action).set_to_current_time()
|
||||
|
||||
|
||||
def log_extra(request: Request | None = None, **kwargs: Any) -> dict[str, Any]:
|
||||
"""Build a standard extra dict for structured logging."""
|
||||
extra: dict[str, Any] = {"request_id": get_request_id(request)}
|
||||
|
||||
Reference in New Issue
Block a user