Build a Homelab Dashboard: Part 5, Telegraf Introduction
As we continue on our homelab dashboard journey, we’re ready to start populating our time-series database (InfluxDB) with some actual data. To do this, we’ll start by installing Telegraf. But, before we dive in, let’s take a at the series so far:
What is Telegraf
In part 1 of this series, I gave a brief overview of Telegraf, but as we did with InfluxDB in our last post, let’s dig a little deeper. Telegraf is a server agent designed to collect and report metrics. We’ll look at Telegraf from two perspectives. The first perspective is using Telegraf to gather statistics about the server on which it has been installed. This means that Telegraf will provide us data like CPU usage, memory usage, disk usage, and the like. It will take that data and send it over to our InfluxDB database for storage and reporting.
The second perspective is using Telegraf to connect to other external systems and services. For instance, we can use Telegraf to connect to a Supermicro system using IPMI or to a UPS using SNMP. Each of these sets of connectivity represents an input plugins The list of plugins is extensive and far too long to list. We’ll cover several of the plugins in future posts, but today we’ll focus the basics. Before we get into the installation, let’s take see what this setup looks like in the form of a diagram:
Looking at the diagram, we’ll see that we have our monitoring server with InfluxDB, Telegraf, and Grafana. Next we have a couple of examples of systems running the Telegraf agent on both Windows and FreeBSD. Finally, we have the other “things” box. This includes our other devices that Telegraf monitors without needing to actually be installed. The coolest part about Telegraf for my purposes is that it seems to work with almost everything in my lab. The biggest miss here is vmWare, which does not have a plugin yet. I’m hoping this changes in the future, but for now, we’ll find another way to handle vmWare.
Installing Telegraf on Linux
We’ll start by installing Telegraf onto our monitoring server that we started configuring way back in part 2 of this series. First we’ll log into our Linux box using PuTTY:
Next, we’ll download the software using the following commands:
sudo wget https://dl.influxdata.com/telegraf/releases/telegraf_1.7.1-1_amd64.deb sudo dpkg -i telegraf_1.7.1-1_amd64.deb
The download and installation should look something like this:
Much like our InfluxDB installation…incredibly easy. It’s actually even easier than InfluxDB in that the service should already be enabled and running. Let’s make sure:
sudo systemctl status telegraf
Assuming everything went well we should see “active (running)” in green:
Now that we have completed the installation, we can move on to configuration.
For the purposes of this part of the series, we’ll just get the basics set up. In future posts we’ll take a look at all of the more interesting things we can do. We’ll start our configuration by opening the config file in nano:
sudo nano /etc/telegraf/telegraf.conf
We mentioned input plugins earlier as it related to getting data, but now we’ll look at output plugins to send data to InfluxDB. We’ll uncomment and change the lines for urls, database, timeout, username, and password:
Save the file with Control-O and exit with Control X. Now we can restart the service so that our changes will take effect:
sudo systemctl restart telegraf
Now let’s log in to InfluxDB make sure we are getting data from Telegraf. We’ll use this command:
influx -username 'influxuser' -password 'influxuserpassword' -database 'TelegrafStats'
Once logged in, we can execute a command to see if we have any measurements:
This should all look something like this:
By default, the config file has settings ready to go for the following:
- Disk IO
These will be metrics only for the system on which we just installed Telegraf. We can also take a look at the data just to get a look before we make it over to Grafana:
SELECT * FROM cpu LIMIT 5
This should show us 5 records from our cpu table:
With that, we have completed our configuration and will be ready to move on to visualizations using Grafana…in our next post.