Grafana Alerts Json for beginners

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.

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.


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

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

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:

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.


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 http://jsonviewer.stack.hu/ creators and maintainers for such a nice json viewer tool.