Grafana — how to create server & service groups using variables

Picture M.B.M. — Unsplash

First time I found myself setting up a monitoring instance composed of Influxdb, Telegraf and Grafana, my biggest dilemma was how to group the various servers by dividing them by services (Docker, Elasticsearch cluster, Apache servers and so on).
The documentation on the official website of Grafana is not very clear about it, so I will try in this very brief tutorial to explain how to create server groups for easier viewing and organization on your dashboards.

IMPORTANT: for this setup you’ll need to tag your server within the agent configuration, in this case i used Telegraf from Influxdata →
If you plan to use another datasource (and another agent ofc) you’ll need to figure it out how to tag your servers.

So, this is the setup i configured:

  • Datasource — InfluxDb
  • Agent — Telegraf
  • Dashboard — Grafana (what else?)

First of all, if you are familiar or not with Telegraf, we need to define a specific tag for our servers in telegraf.conf file, in this case a Docker instance:

# Global tags can be specified here in key=”value” format.
## Environment variables can be used as tags, and throughout the config file
user = “$USER”
group = “DOCKER”

So, all the servers tagged with group = docker will be grouped under a single group.

Now, the funny part.
On Grafana, you need to configure some variables to separate all the servers group with a drop down menu.
To access variable config menu, go to Dashboards →Home →click on the settings icon (right top of the page) →Variables → Add variable

…and this is the configuration i use:

If you’ve configured everything right, you should be able to see your Grafana dashboard menu slightly changed from this kind:

…to this kind:

Last but not least, you can configure different kind of variables for each dashboard. To accomplish this, it’s sufficient to configure variables not from the general config but from specific dashboard variable menu.