Friday, March 29, 2024
HomeLinuxHow to install Telegraf on Ubuntu

How to install Telegraf on Ubuntu

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.

Installing Telegraf

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

#  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

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

#  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.

#  vim /etc/telegraf/telegraf.conf

InfluxDB (Output) – Example

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:

[[outputs.influxdb]]  
urls = ["http://192.168.0.36: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:

# 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:

[[inputs.net]]  
interfaces = ["enp0s3"]

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.

# systemctl status telegraf.service
# systemctl start telegraf.service
# systemctl stop telegraf.service
# systemctl restart telegraf.service

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

Troubleshooting

If you see any issue on telegraf like the metrics are not shipped to influxDB, you can check the logs to get more details, what is going on,

#  tail -f /var/log/telegraf/telegraf.log

Most common issue we observed are:

InfluxDB connection may not established, in that case you can check the connection by “telnet” and if there is no connection, please establish and restart the telegraf service.

Docker Permission may miss to get the docker related metrics. This only applicable for Docker monitoring. To fix this, you can give permission to telegraf using following command.

# usermod -aG docker telegraf

There is few more issues, similar to this, either permission missing or connection is not established. You can check the telegraf.log and fix it.

Also you can run telegraf in docker, please refer following link
https://foxutech.com/monitor-docker-environment/ Also this contains some sample telegraf config for your reference.

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments