(Last Updated On: January 30, 2019)

Telegraf is an agent written in Go for collecting performance metrics from the system it’s running on and the services running on that system. The collected metrics are output to InfluxDB or other supported data stores. From InfluxDB, you should be able to visualize trends and systems performance using tools like Grafana.

A basic usage flow of Telegraf is:

  1. Telegraf agent is installed on all servers ( Ubuntu, Debian, Windows, CentOS e.t.c). It is the configured to collect metrics you want
  2. Metrics collected are pushed to InfluxDB
  3. InfluxDB data source is then added to Grafana
  4. Grafana Graphs are created – They get data from an influxdb data source

I recently covered the installation of Grafana and InfluxDB on Linux; Install InfluxDB on Ubuntu 18.04 and Debian 9, Install Grafana and InfluxDB on CentOS 7, and How to Install Grafana on Ubuntu 18.04 and Debian 9.

How to Install Telegraf on Ubuntu 18.04 LTS

Installation of telegraf on Ubuntu 18.04 is done from Influxdata repository. Once the repo is added, the package can then be installed using an apt package manager. Add the InfluxData repository to the file  /etc/apt/sources.list.d/influxdata.list

cat <<EOF | sudo tee /etc/apt/sources.list.d/influxdata.list
deb https://repos.influxdata.com/ubuntu bionic stable
EOF

Import apt key:

sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -

Update apt index and install telegraf

sudo apt-get update

Install telegraf:

$ sudo apt-get -y install telegraf

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  telegraf
0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded.
Need to get 17.5 MB of archives.
After this operation, 59.9 MB of additional disk space will be used.
Get:1 https://repos.influxdata.com/ubuntu bionic/stable amd64 telegraf amd64 1.9.3-1 [17.5 MB]
Fetched 17.5 MB in 6s (2,715 kB/s)                                                                                                                    
Selecting previously unselected package telegraf.
(Reading database ... 105274 files and directories currently installed.)
Preparing to unpack .../telegraf_1.9.3-1_amd64.deb ...
Unpacking telegraf (1.9.3-1) ...
Setting up telegraf (1.9.3-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/telegraf.service -> /lib/systemd/system/telegraf.service.

Start and enable the service to start on boot up.

$ sudo systemctl enable --now telegraf
$ sudo systemctl is-enabled telegraf
enabled

Check service 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 Wed 2019-01-30 04:03:11 PST; 2min 54s ago
     Docs: https://github.com/influxdata/telegraf
 Main PID: 3385 (telegraf)
    Tasks: 11 (limit: 1110)
   CGroup: /system.slice/telegraf.service
           `-3385 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

Install Telegraf on Debian 9

Add Influx Data repository using the following command:

cat <<EOF | sudo tee /etc/apt/sources.list.d/influxdata.list
deb https://repos.influxdata.com/debian stretch stable
EOF

Import repo gpg key for installing signed packages:

sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -

Update apt index and install telegraf package:

sudo apt-get update
sudo apt-get -y install telegraf

Start telegraf service:

sudo systemctl enable --now start telegraf

You can check the status to confirm if running using:

sudo systemctl status telegraf

Configuring Telegraf

Now that you have InfluxDB and Telegraf running, you can go through our guide on how to Monitor Linux System with Grafana and Telegraf to learn how to configure Telegraf and use it with Grafana.