Monitoring Your Raspberry Pi System using InfluxDB Telegraf

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.

Monitoring Your Raspberry Pi System using InfluxDB Telegraf

Prerequisites

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:

http://Your_RPi_IP_address:8086

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.

InfluxDB Generate All Access API Token

Give a description to the API Token (for example Raspberry-Pi).

Raspberry Pi All Access API Token

After that, copy the API token to a safe place. You won’t be able to see it again.

The new API Token should be on the list of API tokens.

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> \
  --active
  • 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

Installing Telegraf

Run the following commands sequentially to install Telegraf:

wget -q https://repos.influxdata.com/influxdata-archive_compat.key
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.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

The instructions are not working?

If the instructions are not working it might be due to an update on the installation procedure. If that’s the case, we recommend that you go to the next link and follow the official instructions:

Scroll down to the Telegraf section. Select the platform Ubuntu & Debian. Then, copy the commands provided.


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:

export INFLUX_HOST=http://YOUR_RASPBERRY_PI_IP_ADDRESS:8086
export INFLUX_TOKEN=YOUR_API_TOKEN
export INFLUX_ORG=YOUR_ORG_NAME

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.

Starting Telegraf

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.

Telegraf setup instructions

Run that command to start Telegraf. You should get something similar to the next image in your Terminal window.

Run Telegraf Raspberry Pi

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 SystemA collection of useful visualizations for monitoring your system stats”.

Raspberry Pi System Monitoring Template Dashboard

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.

Wrapping Up

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:

Do you like Home Automation? Check our most complete eBook about this subject:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

16 thoughts on “Monitoring Your Raspberry Pi System using InfluxDB Telegraf”

  1. This is very interesting! I have a question though: is it possible to monitor the RP from a different device? I mean having the InfluxDB service running in a RP but the queries being executed from another PC? I am thinking about having a couple of RP running without any screen and being able to monitor their statuses from a laptop, for example. And being able to monitor both devices from one different computer.

    I assume it is possible, so I will try to find out reading the docs, but it would be an interesting project.

    Reply
    • Hi.
      You can access InfluxDB dashboard from any device on the same network as the Raspberry Pi.
      I hope this answers your questions.
      Regards,
      Sara

      Reply
    • Yes, you can. I have 2 pi’s running in 2 different internal networks. And influxdb is running on one of the 2. To be able to reach my influx-environment I’ve a subdomain influxdb.domein where it is pointed to my ‘given’ ip-address. Nginx then handles the connection to the influxdb-environment which is running on http://someip:8086.
      To be able to get data from the second pi I use as INFLUX_HOST the influxdb.domein-value.

      Reply
  2. “No Results” for all the metrics. Yes, originally, I had the bucket set to the name which I called it, but, then linux_host was empty. Then, I saw the last sentence before the “Rapping Up” Section. So, I set the bucket to “rasp-pi” and the linux_host is raspberrypi. No difference. Still “No Results” text displayed for all the metrics. And, I’ve rebooted, as well. Still no output.

    Reply
    • I got this to work after much fiddling around:
      1. I uninstalled and reinstalled influxdb, (not sure these actions where absolutely necessary)
      2. To install influxDB, I used the link in from this article “Install InfluxDB 2 on Raspberry Pi”.
      3. During the Installation of InfluxDB, when creating the initial user, “Setup Initial User” Section, make sure you name the bucket “Raspberry-Pi”. If not, this I believe is what caused the problems I had later. I named my bucket “data-bucket”

      I believe the “Raspberry Pi Template” is expecting the bucket name to be “Raspberry-Pi”.

      In this article, in the “Getting an InfluxDB Token” it states, “Give a description to the API Token (for example Raspberry-Pi)”, I used the bucket name “data-bucket” from when I setup the Initial User. I believe the “Generate API Token” process uses the “Description” field when creating the API Token or something.

      Maybe there is an Influx Environment Variable that can be set for Telegraf to use for the Bucket Name. Therefore, overriding the expected bucket name of “Raspberry-Pi”

      Reply
      • Hi.
        Thanks for sharing your experience with us.
        I’m not sure if that’s what caused the issue. I need to try with another token name and check what happens.
        Regards,
        Sara

        Reply
  3. Typing in :
    telegraf –config http://192.168.1.xxx:8086/api/v2/telegrafs/xxxxxxxxx
    starts a second instance of telegraf that send raspberry pi data to influxdb.

    While that works fine, it only sends data while that command is running. If you do a to get back to the command line that kills the second instance of telegraf and data about the pi stops getting sent to influxdb.

    Do you have any hints about how to add raspberry pi monitoring to always run without needing a command line open? Possibly some changes to /etc/telegraf/telegraf.conf?

    TIA

    Reply
    • Solved it and posted as as response to a question on the RNT Facebook page).

      Here’s what I wrote :

      Out of the box, Telegraf starts automatically as a daemon with its default telegraf.service systemd script. It looks for a configuration file called telegraf.conf in /etc/telegraf/ to run. The default telegraf.conf file basically does nothing so just overwrite it.

      Create a new telegraf.conf by saving your script from the UI :
      Load Data -> TELEGRAF tab -> edit -> DOWNLOAD CONFIG

      Note that the telegraf.conf file gets the values for $INFLUX_HOST, $INFLUX_TOKEN and $INFLUX_ORG from /etc/defaults/telegraf. So you need to have the correct values there. Fill it in something like this :

      INFLUX_HOST=”http://localhost:8086″
      INFLUX_TOKEN=” ”
      INFLUX_ORG=” ”

      or just edit them directly into your config file (Useful if you plan to run multiple instances of telegraf daemons).

      HTH

      Reply
  4. I have an issue with the Influxdb-dashboard. After a refresh it shows like this. And then I hoped to be able to post a picture here but unfortunately not.

    Well, the header with the chosen bucket and linux_host disappears and all metrics show:

    error @3:37-3:38: record is missing label linux_host
    error @2:19-2:20: record is missing label timeRangeStart
    error @2:43-2:44: record is missing label timeRangeStop
    error @1:14-1:15: record is missing label bucket

    If I do a ‘hard’ refresh through F5 everything gets back to normal.

    Reply

Leave a Reply to Tony Cancel reply

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.