Building Dashboards with Grafana

Project status: complete

Objectives

Note: see this other page to find out how to install Docker on Ubuntu.

Docker Compose File

I use docker-compose to run the 3 containers, here is the current docker-compose.yml file (check the Github repository for future changes):

Note: I built a custom-build Docker image for Telegraf because the official one does not include the required SNMP tools.

version: '2'

services:
  influxdb:
    image: "influxdb"
    ports:
      - "8086:8086"
      - "8083:8083"
    volumes:
      - ./data/influxdb:/var/lib/influxdb

  telegraf:
    image: "nuntz/telegraf-snmp"
    volumes:
      - ./data/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro

  grafana:
    image: "grafana/grafana"
    ports:
      - "3000:3000"
    volumes:
      - ./data/grafana/lib:/var/lib/grafana
      - ./data/grafana/log:/var/log/grafana
      - ./data/grafana/etc:/etc/grafana

Each container has one or more volumes defined for data persistency, in ./data/:

The current directory must contain a data directory, and two configuration must be created before running the containers:

Running the Containers

The containers can be started using:

$ sudo docker-compose up

SNMP Configuration for Telegraf

Here is a sample section of the telegraf.conf file for a router (with IP address 192.168.1.1), used to collect interface metrics (based on this example configuration file):

[[inputs.snmp]]
  agents = [ "192.168.1.1:161" ]
  version = 2
  community = "public"

  [[inputs.snmp.field]]
    name = "hostname"
    oid = ".1.3.6.1.2.1.1.5.0"
    is_tag = true

  # IF-MIB::ifTable contains counters on input and output traffic as well as errors and discards.
  [[inputs.snmp.table]]
    name = "interface"
    inherit_tags = [ "hostname" ]
    oid = ".1.3.6.1.2.1.2.2"

    # Interface tag - used to identify interface in metrics database
    [[inputs.snmp.table.field]]
      name = "ifDescr"
      oid = ".1.3.6.1.2.1.2.2.1.2"
      is_tag = true

Creating Panel in Grafana

First, we need to setup the InfluxDB data source:

We can now create our dashboard:

Sample metric to poll interface usage:

SELECT derivative(mean("ifInOctets"), 10s) FROM "interface" WHERE "ifDescr" = 'eth0' AND $timeFilter GROUP BY time($interval) fill(null)