(Last Updated On: May 8, 2018)

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 guide on How to Install InfluxDB on CentOS 7. 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:

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

# yum -y install telegraf

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:

# 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

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.

Also, see:

Monitoring Ceph Cluster with Prometheus and Grafana