Monitoring Dashboard using Telegraf, InfluxDB and Grafana

This solution stack is made up of three components.

  • Telegraf -- A server agent for collecting metrics (CPU, RAM etc.)
  • InfluxDB -- A Time Series Database to store the data.
  • Grafana -- A multiplatform data analytics dashboard.

Telegraf will grab the metrics and send them to InfluxDB to be stored. Grafana will then query InfluxDB and display the metrics on a Dahboard.

InfluxDB

What is InfluxDB?

A time series database (TSDB) is a database optimized for time-stamped or time series data. It's built specifically for handling metrics, events and measurements that are time-stamped and is very good at measuring changes over time.

Installing InfluxDB

Add the Influx Repos:

 Terminal
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

Next, update apt cache, install influxdb and start the Influxdb Daemon

 Terminal
sudo apt-get update && sudo apt-get install influxdb
sudo service influxdb start

Once Influx is running, access the database by running the influx binary.

 Terminal
influx

You will be prompted with a shell. Below are the commands to create the database and create a user. Use the username/password you want.

 InfluxDB
create database rpi_monitoring;
CREATE USER rpi WITH PASSWORD 'rpi' WITH ALL PRIVILEGES;

If you want to see what you created, here are the show commands:

 InfluxDB
show databases;
show users;

Installing Grafana

How to install Grafana

Grab Grafana and extract

 Terminal
cd /opt
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-3.1.1-1470047149.linux-x64.tar.gz
tar -zxvf grafana-3.1.1-1470047149.linux-x64.tar.gz

Then launch the Grafana binary.

 Terminal
cd /opt/grafana-3.1.1-1470047149/bin
./grafana-server

Accessing Grafana Server:

Grafana listens on port 3000, access it per below, replacing the IP with your servers IP address.

 Terminal
http://<IP-SERVER>:3000

Grafana Default Login Credentails

The default login credentials for Grafana is admin/admin

Configure a Data Source

Click the Cogwheel -> Data Source -> Add Data Source

Fill out the information, pointing to your InfluxDB. My configuration looks like this:

Import the Dashboard into Grafana

To import the Raspberry PI Dashboard into Grafana:

Click the + symbol -> Import -> Import via grafana.com

This uses the Dashboard from Grafana.com: https://grafana.com/grafana/dashboards/10578

Installing Telegraf

Installing Telegraf - Ubuntu 20.04

I am using ubuntu 20.04, but it should be a similar process for other releases.

The first step is to add the sources

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

After that we run an apt-update and install telegraf.

 Terminal
apt update
apt install telegraf

Enabling Telegraf

Once installation is complete, we will have to enable the service.

 Terminal
systemctl enable --now telegraf

Telegraf Configuration

Use your favorite editor to edit the telegraf configuration file.

 Terminal
nano /etc/telegraf/telegraf.conf

Once in there, replace the InfluxDB section with the below. Make sure to change the username/password if you are using something different.

 /etc/telegraf/telegraf.conf
[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "rpi_monitoring"
  username = "rpi"
  password = "rpi"

Restarting Telegraf

Restart Telegraf

 Terminal
systemctl restart telegraf