Creating a Dashboard Template - absalon-james/grafanizer GitHub Wiki

A dashboard is a JSON document. When you alter and then save a dashboard in Grafana, the dashboard is saved as a JSON document.

A dashboard template is also a JSON document. It features much of the same JSON as the dashboard. It also features a few fields describing what kind of dashboard template it is. We have SingleEntity and MultiEntity dashboard template types. The key features of a dashboard template are the placeholders that describe what entities and what metrics to apply to the various panels of the dashboard.

It is possible to create a dashboard template by hand however, it is easier to create most of the dashboard in Grafana first, export the JSON, then alter the exported JSON as necessary to create the dashboard template.

Let's say we would like to create a dashboard for every entity that has the CPU idle_percent_metric.

Step 1
Create a grafana dashboard with a single row with a single graph panel that graphs a single metric. Example exported JSON featuring a single row, single panel, single entity graph with a single metric.

Step 2
Wrap the exported JSON with another JSON object and set the following key value pairs in the top level object:

Key Description
type What kind of template? SingleEntity or MultiEntity
tags Additional elastic search tags to add for searching.
user Leave as 'guest' for now
group Leave as 'guest' for now
dashboard Set the value of this key to the exported JSON Object

Your template should now look similar to wrapped exported json.

Step 3
Set the id field of the dashboard. Without setting an ID, a new dashboard for each entity will be created each time. Furthermore, we have access to some information about the entity that we can place in the 'id' and 'title' fields of the dashboard JSON.

{
  "type": "SingleEntity",
  "tags": [],
  "user": "guest",
  "group": "guest",
  "dashboard": {
  "id": "cpu-idle-percent-dashboard-${entity_label}",
  "title": "CPU Idle Percent Dashboard - ${entity_label}",
  ...
}

In the above example, the entity attributes 'entity_label' and 'entity_id' are available as context to the 'id' and 'title' fields.

Step 4
Remove the target section from the graph panel in the JSON and add a metrics section. The metrics section informs grafanizer how to template the targets section.

Remove the section that looks like:

"targets": [
  {
    "target": "rackspace.monitoring.entities.enxxxxxxxx.checks.agent.cpu.chyyyyyyyy.idle_percent_average"
  }
],

Replace it with:

"metrics": [
  {
    "type": "simple",
    "query": "entity().check(label:startswith(cpu)).metric(name:full(idle_percent_average))",
    "target": "rackspace.monitoring.entities.${entity_id}.checks.agent.cpu.${check_id}.${metric_name}"
  }
],

The template will query the entity to determine if the entity has checks starting with cpu and a full match of the metric name idle_percent_average.

Your finished template will should now look like this finished template

If you find that your template does not work, try running grafanizer with the --validate command line argument.