You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this article, we’re going to look at how to Monitor a Linux System with Grafana and Telegraf. Telegraf metrics will be stored on InfluxDB, then we can visualize them on Grafana using a system dashboard.

A prerequisite for this setup is a Linux system and InfluxDB server. You can check our previous guides on:

How to Install InfluxDB on CentOS 7

Install InfluxDB on Ubuntu 18.04 and Debian 9

How to Install InfluxDB on RHEL 8 / CentOS 8

On the same guide, we defined what telegraf and InfluxDB are before demonstrating the installation steps.

Installing Telegraf on CentOS 7

Influxdata provides the repository for installing telegraf on CentOS 7. To add the repository to your system, use the commands:

sudo vim  /etc/yum.repos.d/influxdb.repo

Add the following content:

[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

Update cache to confirm that the repository is working fine:

sudo yum makecache fast

Then install telegraf:

sudo yum -y install telegraf

Installing Telegraf on Ubuntu 18.04 / Debian 9

For a Debian 9 and  Ubuntu 18.04, install telegraf using:

How to Install and Configure Telegraf on Ubuntu 18.04 / Debian 9

Install and Configure Telegraf on RHEL 8 / CentOS 8

Configure telegraf on Linux

A basic telegraf configuration with InfluxDB output and basic inputs to collect system metrics can look like below:

[global_tags]


# Configuration for telegraf agent
[agent]
    interval = "10s"
    debug = false
    hostname = "server-hostname"
    round_interval = true
    flush_interval = "10s"
    flush_jitter = "0s"
    collection_jitter = "0s"
    metric_batch_size = 1000
    metric_buffer_limit = 10000
    quiet = false
    logfile = ""
    omit_hostname = false

###############################################################################
#                                  OUTPUTS                                    #
###############################################################################

[[outputs.influxdb]]
    urls = ["http://influxdb-ip:8086"]
    database = "database-name"
    timeout = "0s"
    username = "auth-username"
    password = "auth-password"
    retention_policy = ""

###############################################################################
#                                  INPUTS                                     #
###############################################################################

[[inputs.cpu]]
    percpu = true
    totalcpu = true
    collect_cpu_time = false
    report_active = false
[[inputs.disk]]
    ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
[[inputs.io]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.system]]
[[inputs.swap]]
[[inputs.netstat]]
[[inputs.processes]]
[[inputs.kernel]]

For a comprehensive list of inputs supported by Telegraf, visit Telegraf inputs Github page.

Replace:

server-hostname with your valid hostname.
http://influxdb-ip:8086 with your valid InfluxDB URL, IP address, and port.
database-name with InfluxDB database name for this host
auth-username with InfluxDB http authentication username.
auth-password with InfluxDB http authentication password.

Once all changes have been made, you can then start and enable the telegraf service:

sudo systemctl start telegraf && systemctl enable telegraf

This will automatically create the InfluxDB database if it doesn’t exist.

Add an InfluxDB data source to Grafana

You need to have Grafana installed, you can follow:

How to Install Grafana on CentOS 7

How to Install Grafana on Ubuntu 18.04 and Debian 9

How to Install Grafana on RHEL 8

Before you can add a dashboard to Grafana for Telegraf system metrics, you need to first import the data source. Login to your Grafana and go to Configuration > Data Sources > Add data source 

Provide the following details:

  • Name – Any valid name
  • Type: InfluxDB
  • HTTP URL: InfluxDB URL address e.g http://localhost:8086 for local db server

Under InfluxDB Details, provide:

  • Database name as defined on telegraf configuration file
  • HTTP authentication username and password as configured on telegraf.

Importing Grafana Dashboard

Once the data source has been added, the next thing is to import the dashboard. I customized one of the dashboards initially created by a user on the community and uploaded it.

Download the dashboard from https://grafana.com/dashboards/5955, it is in JSON format. The head over to Grafana > Import

Select Upload .json and upload downloaded file. Alternatively, you can use Grafana dashboard URL or ID – 5955. Under Options section, give it a unique name and select data source added earlier from the drop-down menu and click the import button.

You should see Metrics being visualized immediately.

telegraf grafana dashboard

Also, see:

Ctop – Top command for container metrics

How to Optimize Linux System with Stacer

Monitoring Ceph Cluster with Prometheus and Grafana

How to Monitor Redis Server with Prometheus and Grafana in 5 minutes

How to Monitor Linux Server Performance with Prometheus and Grafana in 5 minutes

How to Monitor BIND DNS server with Prometheus and Grafana

Monitoring MySQL / MariaDB with Prometheus in five minutes

As an appreciation for the content we put out,
we would be thrilled if you support us!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

LEAVE A REPLY

Please enter your comment!
Please enter your name here