DocsDiscoveryHealth History & Uptime

Health History & Uptime

Every change of state of a health check is recorded as a transition. From this timeline the platform derives uptime, time in critical, incidents and MTTR per asset, both live (API) and as a nightly per-day rollup.


Overview

HealthStatus keeps the current state of each check (Prometheus Blackbox probes, Alertmanager alerts). Since story 8.1 every change of that state also writes a HealthTransition row with the check key (asset, source_type, source_identifier, check_type), from_status, to_status, the message and the instant (at). History starts at the deploy of this feature: there is no backfill of earlier states. Both history tables are view-only in the Django admin (Monitoring → Health transitions, Health daily statistics).

Transitions

A transition is written only when the state of a check changes:

  • a new check: from_status is empty
  • a different state: from_status is the previous state, to_status the new one
  • an inactive check that becomes active again: from_status is empty
  • a check deactivated because the last collection did not refresh it (alert resolved, target removed): to_status is empty
  • an unchanged state on an active check writes nothing

Asset state and definitions

At any instant the state of an asset is the worst state among its active checks, with the same priority as the monitoring traffic light: critical > degraded > unknown > healthy. An asset without active checks is not monitored: that time counts in no state.

  • uptime %: (healthy + degraded) / (healthy + degraded + critical) × 100, 2 decimals; null when there is no known time (unknown is excluded)
  • incidents: entries of the asset state into critical inside the period; a critical state already in progress at the start is not a new incident
  • MTTR: mean duration of the critical episodes that started and ended inside the window; null when there is none

Daily rollup

The Celery task rollup_health_daily runs every day at 00:20 UTC (beat entry rollup-health-daily) and stores one HealthDailyStat row per asset for the UTC day [00:00, 24:00) just ended: healthy_seconds, degraded_seconds, critical_seconds, unknown_seconds and incidents. A state that started before midnight counts for its share of the day. Assets not monitored during the day get no row. Running it again for the same day replaces its rows; it accepts an ISO day (YYYY-MM-DD) and rejects any other value, today and future days.

docker exec idp-backend python manage.py shell -c "from apps.monitoring.tasks import rollup_health_daily; print(rollup_health_daily(day='2026-11-27'))"

Uptime API

GET /api/v1/monitoring/assets/<uid>/uptime/?range=30d returns the numbers of the window [now − N days, now], computed live from the transitions (today included). range is <days>d, default 30d, at most HEALTH_HISTORY_RETENTION_DAYS (400 when the retention is disabled); any other value returns 400, an unknown asset 404. Any authenticated user can call it.

{
  "asset_uid": "azure:vm:web-01",
  "range_days": 30,
  "from": "2026-10-30T12:00:00Z",
  "to": "2026-11-29T12:00:00Z",
  "uptime_percent": 99.72,
  "seconds": {"healthy": 2580000, "degraded": 4800, "critical": 7200, "unknown": 0},
  "critical_seconds": 7200,
  "incidents": 2,
  "mttr_seconds": 3600
}

Retention

HEALTH_HISTORY_RETENTION_DAYS (default 400, 0 = keep forever) is applied by the nightly prune_old_records task to transitions and daily statistics. For every check the last transition before the cutoff is always kept, because it gives the state at the start of a window.