This guide will show you how to monitor your Raspberry Pi system using InfluxDB Telegraf. You can collect metrics from the Raspberry Pi board (CPU usage, memory usage, disk usage, system load, CPU and GPU temperatures, and other useful data) to monitor the system using InfluxDB Telegraf. Telegraf is InfluxData’s data collection agent for collecting and reporting metrics.
Before proceeding you must have InfluxDB installed on your Raspberry Pi. Follow the next tutorial:
Raspberry Pi Monitoring Template
There is an InfluxDB template that can be used to monitor your Raspberry Pi Linux system. An InfluxDB template is a prepackaged set of InfluxDB configurations that contain everything from dashboards and Telegraf configurations to notifications and alerts.
Templates reduce the setup time by giving you resources that are already configured for your use case. In this case, you’ll get a set of configurations that are ready to use to monitor your Raspberry Pi. To learn more about InfluxDB templates, you can check the following link:
We’ll use the Raspberry Pi Monitoring template that includes the following:
- one bucket: rasp-pi (7d retention)
- labels: raspberry-pi + Telegraf plugin labels
- Diskio input plugin
- Mem input plugin
- Net input plugin
- Processes input plugin
- Swap input plugin
- System input plugin
- one Telegraf configuration
- one dashboard: Raspberry Pi System
- two variables: bucket and linux_host
Follow the next instructions to install the Raspberry Pi Monitoring template.
Getting an InfluxDB Token
You need to get an InfluxDB token to be able to install the Raspberry Pi Monitoring template using Influx CLI (command line interface).
Go to your InfluxDB Interface:
Once you’re on InfluxDB, on the left sidebar click on Data/Load Data and then, select the API Tokens tab. Click on the + Generate API Token to generate a new API Token. We’ll generate an All Access API Token.
Give a description to the API Token (for example Raspberry-Pi).
The new API Token should be on the list:
Click on the API Token name to check the API token. You can save it in a safe place because you’ll need it in a moment.
Installing Influx CLI
Influx CLI is InfluxDB command line interface that contains commands to manage many aspects of InfluxDB, including buckets, organizations, users, tasks, etc. It should be automatically installed when you install InfluxDB.
Provide required authentication credentials
To avoid having to pass your InfluxDB host, API token, and organization with each command, you can store them in an influx CLI configuration (config). For that, you need to use the influx config create command and pass your information.
First, edit the following command with your information:
influx config create --config-name influx-config \
--host-url http://YOUR_RASPBERRY_PI_IP_ADDRESS:8086 \
--org <your-org> \
--token <your-auth-token> \
- Replace YOUR_RASPBERRY_PI_IP_ADDRESS with your Pi’s IP address.
- Replace <your-org> with your InfluxDB organization name
- Replace the <your-auth-token> with the API token you got in the previous step.
For example, in my case, the command looks as follows:
influx config create --config-name influx-config \ --host-url http://192.168.1.106:8086 \ --org RNT \ --token v_od_mG--9_srf_OnaaODihPDX34suToP7XEH47v6x77CMxakZaoYHzF7Ec9mLT-CuXXXXXXXXXXXXXXXXXvQCSSw== \ --active
Applying the Raspberry Pi Template
Now, run the following command to apply the Raspberry Pi template.
influx apply -u https://raw.githubusercontent.com/influxdata/community-templates/master/raspberry-pi/raspberry-pi-system.yml
Run the following commands sequentially to install Telegraf:
wget -q https://repos.influxdata.com/influxdb.key
echo '23a1c8836f0afc5ed24e0486339d7cc8f6790b83886c4c96995b88a061c5bb5d influxdb.key' | sha256sum -c && cat influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
sudo apt-get update && sudo apt-get install telegraf
Now, you need to add the following environment variables to your Telegraf environment:
- INFLUX_HOST: InfluxDB URL http://YOUR_RASPBERRY_PI_IP_ADDRESS:8086
- INFLUX_TOKEN: Your InfluxDB Cloud API token
- INFLUX_ORG: Your InfluxDB Cloud organization name.
For that, edit the following command with your own details:
For example, in my case, the command looks as follows:
export INFLUX_HOST=http://192.168.1.106:8086 export INFLUX_TOKEN=v_od_mG--9_srf_OnaaODihPDX34suToXXXXXXXXXXP7XEH47v6x export INFLUX_ORG=RNT
Then, run it on your Raspberry Pi.
Now, restart Telegraf with the following command:
sudo systemctl reload telegraf.service
Start Telegraf as a service. For the exact command, you need to go to your InfluxDB interface, and then Data/Load Data > Telegraf. Click on the rpi Setup Instructions. Copy the command to start Telegraf.
Run that command to start Telegraf. You should get something similar to the next image in your Terminal window.
At the moment, Telegraf should be collecting data from the Raspberry Pi and sending it to the corresponding bucket on InfluxDB.
Raspberry Pi System Dashboard
Now you can monitor your Raspberry Pi system on a Dashboard in InfluxDB. In your InfluxDB user interface, go to Boards/Dashboards (left sidebar) and click on the Raspberry Pi System “A collection of useful visualizations for monitoring your system stats”.
You’ll get access to the Raspberry Pi System Dashboard. You can check useful information like the CPU and GPU temperatures, total memory, memory usage, and much more.
If you don’t see any data on the dashboard, make sure you select the right bucket rasp-pi and the linux_host is raspberrypi.
Congratulations! You set up an InfluxDB Telegraf to monitor your Raspberry Pi system.
In this quick guide, we’ve shown you how to use InfluxDB Telegraf to collect useful data from your Raspberry Pi and display it on a dashboard. You can monitor CPU usage, memory usage, disk usage, system load, CPU and GPU temperatures, and other useful data.
We hope you find this tutorial useful. We have other InfluxDB tutorials you may like:
- ESP32: Getting Started with InfluxDB
- ESP8266 NodeMCU: Getting Started with InfluxDB
- ESP32/ESP8266: Send BME280 Sensor Readings to InfluxDB
Thanks for reading.