Skip to content

Grafana Module API Explanation

The Grafana module tracks configured monitoring dashboards and active firing alert rules.


API Execution Logic

The module locates the service entry matching the identifier grafana. It retrieves the bearer token from the GRAFANA_TOKEN (or GRAFANA_API_KEY) environment variable and passes it via the Authorization: Bearer [TOKEN] header.

Request Execution

The backend process executes two separate fetch requests:

  1. Dashboards Query: A request is sent to /api/search to retrieve the list of configured dashboards.
  2. Alerts Query: A request is sent to /api/alertmanager/grafana/api/v2/alerts to retrieve active alert states from Grafana's embedded Alertmanager.

Data Parsing

  • Dashboards: The JSON response from /api/search is parsed as an array. The length of this array represents the total number of dashboards.
  • Alerts: The module loops through the alerts returned by the alertmanager endpoint. It counts an alert only if its status state is set to active, its inhibitedBy array is empty, and its silencedBy array is empty.

Metric Calculation

  • Primary Metric: The total number of configured dashboards.
  • Secondary Metric: The count of active, non-silenced firing alerts.

Caching Strategy

The dashboard and alert metrics are cached in memory for 60 seconds (TTL) with a stale window of up to 300 seconds. Request timeouts are set to 5 seconds per call.