Raspberry Pi 4+ with Influx, TeleGraf, and Grafana to monitor sensor data

Let's look at setting up a multi-purpose device for an Infrastructure to Go (ItG) project. Grafana is a Graphical User Interface (GUI) to visually see the data produced by TeleGraf by using an Influx data source. This will help you be able to see your payload prior to sending it off. Let’s begin!

https://images.hdqwalls.com/wallpapers/raspberry-pi-logo-h0.jpg

Let’s first install Grafana.

  1. Update your Pi first:
sudo apt update
sudo apt upgrade

2. Download Grafana Package

wget https://dl.grafana.com/oss/release/grafana_6.6.1_armhf.deb sudo dpkg -i grafana_6.6.1_armhf.deb

3. Enable Grafana for Restart Purposes

sudo systemctl enable grafana-server

4. Start Grafana

sudo systemctl start grafana-server

5. You can test it with:

localhost:3000

Username: admin

Password: admin

Of course, if you are SSH’d to your PI then use your <IP address> then the port.

Connecting a Data Source with Influx

  1. Setup the keys to download Influx
wget -qO- https://repos.influxdata.com/influxdb.key | sudo tee /etc/apt/sources.list.d/influxdb.list test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

2. Now use apt to install Influx

sudo apt-get update && sudo apt-get install influxdb

3. Now Start Influx

sudo service influxdb start

4. Check the status of Influx

sudo service influxdb start

Example Status:

● influxdb.service - InfluxDB is an open-source, distributed, time series database
Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-06-23 23:13:16 CDT; 1s ago
Docs: https://docs.influxdata.com/influxdb/
Main PID: 17581 (influxd)
Tasks: 12 (limit: 4915)
CGroup: /system.slice/influxdb.service
└─17581 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

Now to set up our Sensor Collector — Telegraf

  1. Download Telegraf
wget https://dl.influxdata.com/telegraf/releases/telegraf_1.12.2-1_armhf.deb

2. Install the Telegraf package

sudo dpkg -i telegraf_1.12.2-1_armhf.deb

3. Of course, if you were collecting data; then you could run your python script now.

Example:

nohup python3 sensor-collecting-script.py &

Setting up the Influx to Grafana as a Data Source

  1. Access Grafana and Go to Data Sources
Example of Data source with Influx DB Added

2. Click Add Data Source

Leave localhost:8086 unless you're using another IP address.

Database: telegraf

User: User

3. Save & Test

Setting up a Pre Set Dashboard to Monitor the PI

We are going to use a preset dashboard that we can use to monitor the PI itself.

  1. Go to Manage on Dashboard and Click Import
  2. Use import id: 10578

3. Now you select the Influx data source.

That's IT! You now have a running dashboard with Grafana; a database to collect data; and a sensor collector for all your fun projects! Happy PIing.

Enterprise Solution Architect | Certified Kubernetes Administrator ⚓ | SAFe SPC | LeSS Practioner | AWS Solutions Architect | Dev*Ops/GitOps Engineer 🔥

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store