How to Install Telegraf Configure InfluxDB2 output in Debian 11

In this guide we are going to learn how to install Telegraf and configure InfluxDB v2 output on a Debian 11.

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 apt update
sudo apt -y upgrade

2. Installing Telegraf

Telegraf is not available in default Debian 11 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_amd64.deb

Now install the downloaded package:

sudo dpkg -i telegraf_1.20.4-1_amd64.deb

Confirm that the package was installed successfully

$ apt-cache policy telegraf
telegraf:
  Installed: 1.20.4-1
  Candidate: 1.20.4-1
  Version table:
 *** 1.20.4-1 500
        500 https://repos.influxdata.com/debian bullseye/stable amd64 Packages
        100 /var/lib/dpkg/status

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 Debian 11, the service is started by default. 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 (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-12-07 07:52:35 UTC; 2min 29s ago
       Docs: https://github.com/influxdata/telegraf
   Main PID: 25143 (telegraf)
      Tasks: 8 (limit: 4626)
     Memory: 43.4M
        CPU: 345ms
     CGroup: /system.slice/telegraf.service
             └─25143 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

Dec 07 07:53:25 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:53:25Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:53:35 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:53:35Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:53:45 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:53:45Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:53:55 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:53:55Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:54:05 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:54:05Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:54:15 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:54:15Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:54:25 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:54:25Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:54:35 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:54:35Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:54:45 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:54:45Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
Dec 07 07:54:55 ip-10-2-40-122 telegraf[25143]: 2021-12-07T07:54:55Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):

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 /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

Conclusion

In this guide we installed Telegraf and configured InfluxDB v2 output on a Debian 11 system.

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