Created , Updated


Problem: Transition from legacy alerts to enhanced alerting system

Grafana provides two different possibilities for alerts:

  • Legacy dashboard alerts which are deprecated and will be removed in Grafana 9

  • An enhanced alerting system which was introduced with Grafana 8

Legacy alerts are incompatible with Grafana’s enhanced alerting system. As consequence, if you want to use Grafana’s improved altering system, all existing legacy alerts need to be migrated.

Secondary issue: Grafana lacks support for template variables

Both alerting systems don’t support template variables which are used in some of our dashboards. This guide will recommend how to circumvent these limitations.

Legacy dashboard alerts

In general, we recommend to use Grafana’s enhanced alerting system. Some of our dashboards utilize template variables and transformations. Those need to be replaced in order to use these dashboards in conjunction with legacy dashboard alerts. This requires a considerable amount of work.

Transformations

In most cases, transformations are used in panels for naming purposes. We recommend to simply delete these transformations. A few panels use transformations for e.g. binary operations. Those panels need to be overhauled in such a way that they work without transformations.

Template variables

Template variables can be configured in tab Variables of the Dashboard settings. They are used to dynamically query the configured data source to help visualizing its data. In order to use this dashboard in conjunction with legacy alerts template variables need to be removed from the dashboard entirely.

Before doing that template variables have to be replaced in such a way that their initial purpose is maintained, at least in a static context. For that the type of a template variable needs to be considered.

Query

We use a template variable of type Query to determine the possible values of a variable in a configured data source. For example, the template variable queueManager in our z/OS MQ Dashboard queries the data source to list all available queue managers. This enables the user to filter for a specific queue manager in the z/OS MQ Dashboard.

In order to remove a template variable of type Query follow the subsequent steps:

  • For every value, the chosen dashboard needs to be duplicated.

  • Export the duplicated dashboard as JSON file.

  • Replace all occurrences of ${<templateVariableName>} with a respective value in the JSON file.

  • Delete the former duplicated dashboard and import the modified JSON file in Grafana.

  • Remove the affected template variable of the imported dashboard.

Interval

As for now we only use one template variable of type Interval called ${windowPeriod} to define the aggregation window granularity for time series.

In order to remove the template variable ${windowPeriod} follow the subsequent steps:

  • Export the current dashboard as JSON file.

  • Replace all occurrences of ${windowPeriod} with v.windowPeriod or a time span of your choosing which is supported by Grafana(1s, 1m, 1h, 1d,…).

  • Delete the former dashboard and import the modified JSON file in Grafana.

  • Remove the template variable ${windowPeriod} of the imported dashboard.

Constant

We use template variables of type Constant as placeholders for bigger mathematical terms, which allows us to adjust them for all concerned queries quickly and keep queries more human readable.

In order to remove a template variable of type Constant follow these steps:

  • Export the relevant dashboard as JSON file.

  • Replace all occurrences of ${<templateVariableName>} with its value in the JSON file.

  • Delete the former dashboard and import the modified JSON file in Grafana.

  • Remove the replaced template variable of the imported dashboard.

Enhanced alerting system

Fortunately, using the enhanced alerting system, alerts are no longer coupled with a specific dashboard. This means a dashboard that uses transformations or template variables doesn’t need to be modified. However, template variables can’t be used in alert queries and must be replaced with an appropriate value.