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.
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.
- How to Install & Configure InfluxDB2 in Rocky Linux/CentOS 8
- How to install and configure Grafana in Rocky Linux/Centos 8
- Installing and setting up Grafana in linux
- Monitor Multiple Servers With Grafana, Influxdb & Telegraf
Table of Content
- Esuring the server is up to date
- Installing Telegraf
- Starting and enabling Telegraf Service
- 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 : [email protected] 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: telegraf.service: Succeeded. Dec 02 13:05:06 cloudsrv.citizix.com systemd: Stopped The plugin-driven server agent for reporting metrics into InfluxDB. Dec 02 13:05:06 cloudsrv.citizix.com systemd: Started The plugin-driven server agent for reporting metrics into InfluxDB. Dec 02 13:05:06 cloudsrv.citizix.com telegraf: 2021-12-02T10:05:06Z I! Starting Telegraf 1.20.4 Dec 02 13:05:06 cloudsrv.citizix.com telegraf: 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: 2021-12-02T10:05:06Z I! Loaded aggregators: Dec 02 13:05:06 cloudsrv.citizix.com telegraf: 2021-12-02T10:05:06Z I! Loaded processors: Dec 02 13:05:06 cloudsrv.citizix.com telegraf: 2021-12-02T10:05:06Z I! Loaded outputs: influxdb_v2 Dec 02 13:05:06 cloudsrv.citizix.com telegraf: 2021-12-02T10:05:06Z I! Tags enabled: host=cloudsrv.citizix.com Dec 02 13:05:06 cloudsrv.citizix.com telegraf: 2021-12-02T10:05:06Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"cloudsrv.citizix.com", Flush Interval:10s
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 /etc/telegraf/telegraf.conf
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
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.