Post

Installing Telegraf on Ubuntu

Hi there! This post is part of a series I am doing where I attempt to move most of the applications I use at home over to Linux. If you find this interesting you may enjoy the other posts too!

Telegraf is the open source server agent to help you collect metrics from your stacks, sensors and systems. Following the steps below should get you up and running with Telegraf in no time. Should you want to dive a bit deeper into some of the features offered by Telegraf you may want to refer to the official documentation here.

First Time Only

The first time you install any of the Influx Data products you will need to add their repository using the below commands:

1
2
3
sudo 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

Installing Telegraf

Once you have added the InfluxData source to your system, you can install Telegraf with the below command:

1
sudo apt-get update && sudo apt-get install telegraf

Configuring Telegraf

Once installed, you will need to make some changes to the default configuration file that Telegraf ships with. To do this we can edit the telegraf.conf file.

1
sudo nano /etc/telegraf/telegraf.conf

InfluxDB (Output)

You will need to enable at least 1 output for Telegraf, in my case (and most commonly) this would be InfluxDB. Search for the [[outputs.influxdb]] configuration section and change as needed, my configuration is shown below:

1
2
3
[[outputs.influxdb]]
  urls = ["http://10.0.0.56:8086"]
  database = "telegraf"

net (Input)

To collect networking stats for your computer you will need to enable the [[inputs.net]] plugin. Part of the configuration for the plugin is setting the interface name for your network card (the name varies from system to system) - the easiest way to get your interface name is by listing all the networking devices on your computer and choosing the most appropriate one from the results:

1
ls /sys/class/net/

Once you have your adapter name change your configuration to match it, in my case I am using the following configuration:

1
2
[[inputs.net]]
  interfaces = ["eno1"]

Default (Input)

When installing Telegraf on my system the following plugins seemed to be enabled by default (though your mileage may vary):

A complete list of Telegraf plugins can be found here.

Service Management

You can use the below commands to manage the Telegraf service after making configuration changes.

1
2
3
4
sudo systemctl status telegraf.service
sudo systemctl start telegraf.service
sudo systemctl stop telegraf.service
sudo systemctl restart telegraf.service

Make sure you remember to restart the service after making configuration changes.

Troubleshooting

Should you run into any issues with starting Telegraf, or you are missing data you can always run the below command to get the last couple of messages from Telegraf:

1
sudo systemctl status telegraf.service

Should the above not provide you any insight you could always run cat and grep on syslog to listen for new Telegraf events and print them to your screen:

1
tail -f /var/log/syslog | grep telegraf

In my case I had set the incorrect URL for InfluxDB :/

All Done

Hopefully you find this post helpful!

Feel free to leave any feedback or comments below, or if you spot an issue let me know so I can fix it. Happy monitoring!

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.