How to Install Telegraf Configure InfluxDB2 output in Rocky Linux/CentOS 8

In this guide we are going to learn how to install Telegraf and configure InfluxDB v2 output on a Rocky Linux server 8. This guide also works for any RHEL 8 based server like Alma Linux 8, Centos 8, Oracle Linux 8 etc.

Telegraf is a plugin-driven server agent for collecting & reporting metrics, and is the first piece of the TICK stack. Telegraf has plugins to source a variety of metrics directly from the system it’s running on, pull metrics from third-party APIs, or even listen for metrics via a statsd and Kafka consumer services. It also has output plugins to send metrics to a variety of other datastores, services, and message queues, including InfluxDB, Graphite, OpenTSDB, Datadog, Librato, Kafka, MQTT, NSQ, and many others.

Key features

Here are some of the features that Telegraf currently supports that make it a great choice for metrics collection.

  • Written entirely in Go. It compiles into a single binary with no external dependencies.
  • Minimal memory footprint.
  • Plugin system allows new inputs and outputs to be easily added.
  • A wide number of plugins for many popular services already exist for well known services and APIs.

Also check

Table of Content

  1. Esuring the server is up to date
  2. Installing Telegraf
  3. Starting and enabling Telegraf Service
  4. Configuring Telegraf output to InfluxDB

1. Esuring the server is up to date

Before proceeding let us ensure that our server packages are updated. Use this command to achieve this

sudo dnf -y update

2. Installing Telegraf

Telegraf is not available in default Rocky Linux repos. Influxdata the company behind Telegraf and InfluxDB provides an rpm package that can be downloaded from it’s site.

Download the packagee

curl -LO -C - https://dl.influxdata.com/telegraf/releases/telegraf-1.20.4-1.x86_64.rpm

Now install the downloaded package:

sudo dnf localinstall ./telegraf-1.20.4-1.x86_64.rpm

Confirm that the package was installed successfully

$ rpm -qi telegraf
Name        : telegraf
Version     : 1.20.4
Release     : 1
Architecture: x86_64
Install Date: Thu 02 Dec 2021 11:58:20 AM EAT
Group       : default
Size        : 132470197
License     : MIT
Signature   : (none)
Source RPM  : telegraf-1.20.4-1.src.rpm
Build Date  : Wed 17 Nov 2021 11:26:25 PM EAT
Build Host  : 183b8c051625
Relocations : /
Packager    : support@influxdb.com
Vendor      : InfluxData
URL         : https://github.com/influxdata/telegraf
Summary     : Plugin-driven server agent for reporting metrics into InfluxDB.
Description :
Plugin-driven server agent for reporting metrics into InfluxDB.

Telegraf is now installed in the system.

3. Starting and enabling the InfluxDB Service

Once the installation is done, we need to start the service. In RHEL based systems, the service is not started by default. Start it using this command:

sudo systemctl start telegraf

Confirm that the service was started successfully using this command:

$ sudo systemctl status telegraf
● telegraf.service - The plugin-driven server agent for reporting metrics into InfluxDB
   Loaded: loaded (/usr/lib/systemd/system/telegraf.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-12-02 13:05:06 EAT; 5h 6min ago
     Docs: https://github.com/influxdata/telegraf
 Main PID: 140411 (telegraf)
    Tasks: 8 (limit: 23168)
   Memory: 48.0M
   CGroup: /system.slice/telegraf.service
           └─140411 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

Dec 02 13:05:06 cloudsrv.citizix.com systemd[1]: telegraf.service: Succeeded.
Dec 02 13:05:06 cloudsrv.citizix.com systemd[1]: Stopped The plugin-driven server agent for reporting metrics into InfluxDB.
Dec 02 13:05:06 cloudsrv.citizix.com systemd[1]: Started The plugin-driven server agent for reporting metrics into InfluxDB.
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! Starting Telegraf 1.20.4
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! Loaded inputs: cpu disk diskio kernel mem processes swap system
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! Loaded aggregators:
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! Loaded processors:
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! Loaded outputs: influxdb_v2
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! Tags enabled: host=cloudsrv.citizix.com
Dec 02 13:05:06 cloudsrv.citizix.com telegraf[140411]: 2021-12-02T10:05:06Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"cloudsrv.citizix.com", Flush Interval:10s

The Active: active (running) in the output confirms that the service was started successfully.

To enable the service to start on boot, use this command:

sudo systemctl enable telegraf

4. Configuring Telegraf output to InfluxDB

For this to work we need to have InfluxDB up and running on a server reeachable. If you don’t yet have influxdb installed, check out this guide here.

Creating influxdb bucket and user

Once Influx DB is setup and installed, please add a telegraf user that will be used to send the data. The following operations are performed on a system authorized to access influxdb.

Create bucket for telegraf with data retention for 6 months (

4380h).
$ influx bucket create --org citizix --name telegraf --retention 4380h
ID			Name		Retention	Shard group duration	Organization ID		Schema Type
3230c5ca8153dcd8	telegraf	4380h0m0s	168h0m0s		9d8c5d7565722d99	implicit

Then create a telegraf user

$ influx user create --name telegraf --org citizix --password SecretP4ss!
ID			Name
088aa327efb63000	telegraf

Then authorizations are defined for the user, in the example below, the user telegraf is allowed to read and writes in its organization buckets

$ influx auth create --user telegraf --read-buckets --write-buckets
ID			Description	Token												User Name	User ID			Permissions
088aa43d6c363000			52_9XBWNnygV2F_6axNezT5Xr-pkW4SX6xktLlfC5IQZxo4twvvj3B1W7nwU6FNcq0p7eE47NOD6rbGn6yyGGg==	telegraf	088aa327efb63000	[read:orgs/9d8c5d7565722d99/buckets write:orgs/9d8c5d7565722d99/buckets]

Configuring Telegraf to send data

The telegraf config file is located in this path /etc/telegraf/telegraf.conf. Open the config file using your text editor

sudo vim <span style="font-size: calc(11px + 0.2em);">/etc/telegraf/telegraf.conf</span>

Comment out everything in the section [[outputs.influxdb]] and add this:

[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = Auth token here"
  organization = "citizix"
  bucket = "telegraf"

Save and exit the file. Then restart telegraf

sudo systemctl restart telegraf

Now the data is being sent to InfluxDB

Conclusion

In this guide we installed Telegraf and configured InfluxDB v2 output on a Rocky Linux server 8. This guide also works for any RHEL 8 based server like Alma Linux 8, Centos 8, Oracle Linux 8 etc.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy