Grafana Alerts Json for beginners

Understand Grafana Alerts Json

What are Grafana Alerts?

Grafana alerts are a must-have to keep an eye on your infrastructure’s golden signals. You define a metric, a rule on it, a notification channel and your good to go. Everything’s accessible in a centralized control panel.

Grafana Alerts Panel

Why is it important to work with alerts in json format?

Although the Grafana UI works great to create and manage alerts, exporting and importing alerts dashboards in between different versions and implement those changes in CI/CD may require the kind of debugging only feasibly through directly editing the json file.

Grafana alerts dashboard json

Lets extract the json file. First, go to the dashboard you want to work with and click on the settings button in the top-right corner. I would recommend that you create an Alerts Dashboard where you query the metrics on which you wish to create alerts.

An Alerts Dashboard. Notice the green hearth next to the graph’s title.
Top right dashboard settings

Then, to the left, click the JSON model button:

JSON Model access

My actual JSON has almost 1.5k lines. So, we need to understand whats going on.

General Grafana dashboard Json structure

We find a structure where one special array is in our interest: panels. It contains all the dashboard’s visible elements like titles and panels, and some basic settings. In my case, I have 12 elements as we may see in next image:

Panels elements

The first panel I have available with an alert configured is in position 2, which represents a Time Series graph. Here we find an alert dictionary were the details are defined.

Among the different parameters in alerts.conditions which can be easily matched with the GUI, the query.params.0 and the evaluator.params.0 may be the more difficult to identify. The first relates to the PromQL query being followed, the second is the threshold value over which the alert should trigger for that query.

Grafana Alerts first part.
The A query referenced in the params.0 position.

The remaining configuration is pretty straight forward, except .for and .frequency frequency, which establish the frequency Grafana will check this alert and for how long it can be over the threshold to actually fire the alarm.

One question remains…

Grafana Alerts have a Notification Channels configuration in its GUI where a notification service must be setup for managing and proper alerting. This setting is not available in any Json I’ve inspected.

According to this thread, this feature is not implemented yet in Grafana.

Special thanks to creators and maintainers for such a nice json viewer tool.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store