Press "Enter" to skip to content

Installing Telegraf on Ubuntu 20.04

bist 0

Install Telegraf from InfluxData Repos

If you want to install it from the InfluxData repos to ensure seamless updates whenever there are new releases, simply create the InfluxData repos as follows;

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
apt update
apt install telegraf

Once the installation is done, you can start and enable Telegraf to run on system boot (This is usually done automatically during installation);

systemctl enable --now telegraf

Configuring Telegraf to Collect System Metrics

is a plugin-driven server agent for collecting and sending metrics and events from databases, systems, and IoT sensors. All metrics are gathered from the declared inputs, and sent to the declared outputs. It is basically made up of four distinct plugin types:

/etc/telegraf/telegraf.conf is the default Telegraf configuration file.

In this tutorial, we will configure TIG stack monitor system memory usage, system processes, disk usage, system load, system uptime and logged in users.

As such, we will generate our custom Telegraf configuration with the above specified metrics on the input filter. Custom Telegraf configuration file can be generated with telegraf command.

Create a backup of the original Telegraf configuration file.

mv /etc/telegraf/telegraf.conf{,.old}

Generate the Custom Telegraf for the specified metrics;

telegraf config -input-filter cpu:mem:swap:system:processes:disk -output-filter influxdb > /etc/telegraf/telegraf.conf

Read more about Telegraf input plugins on Telegraf Plugins Github page.

Once the configuration file is generated, edit it to define the connection details to InfluxDB metrics database;

nano /etc/telegraf/telegraf.conf

Replace the InfluxDB database connection details accordingly.

###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################


# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "telegraf"
  username = "telegraf"
  password = "myP@SSword"

Restart Telegraf after modifications;

systemctl restart telegraf

Recheck the status;

systemctl status telegraf
● telegraf.service - The plugin-driven server agent for reporting metrics into InfluxDB
     Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-05-30 16:43:07 UTC; 8s ago
       Docs: https://github.com/influxdata/telegraf
   Main PID: 4776 (telegraf)
      Tasks: 10 (limit: 2282)
     Memory: 10.1M
     CGroup: /system.slice/telegraf.service
             └─4776 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

May 30 16:43:07 ubuntu20 systemd[1]: Started The plugin-driven server agent for reporting metrics into InfluxDB.
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! Starting Telegraf 1.14.3
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! Loaded inputs: swap system cpu disk diskio kernel mem processes
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! Loaded aggregators:
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! Loaded processors:
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! Loaded outputs: influxdb
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! Tags enabled: host=ubuntu20
May 30 16:43:07 ubuntu20 telegraf[4776]: 2020-05-30T16:43:07Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"ubuntu20", Flush Interval:10s

Start Telegraf and Verify If data appears

Telegraf enables you to run configuration tests outputing metrics to stdout. To run a general test for all metrics defined;

telegraf --config /etc/telegraf/telegraf.conf --test

To run configuration test for a specific metric for example, system input plugin;

telegraf -test -config /etc/telegraf/telegraf.conf --input-filter system
2020-05-30T11:07:42Z I! Starting Telegraf 1.14.3
> system,host=ubuntu20 load1=0.01,load15=0,load5=0.02,n_cpus=2i,n_users=2i 1590836862000000000
> system,host=ubuntu20 uptime=9206i 1590836862000000000
> system,host=ubuntu20 uptime_format=" 2:33" 1590836862000000000

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.