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:
- Dashboards Query: A request is sent to
/api/searchto retrieve the list of configured dashboards. - Alerts Query: A request is sent to
/api/alertmanager/grafana/api/v2/alertsto retrieve active alert states from Grafana's embedded Alertmanager.
Data Parsing
- Dashboards: The JSON response from
/api/searchis 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, itsinhibitedByarray is empty, and itssilencedByarray 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.