Telegraf Deployment Guide#
The following instructions are for deploying the Telegraf agent.
Prerequisites#
This guide is written for a Red Hat Enterprise Linux 8 based operating system which is operating within a cluster of systems and the following are the prerequisites:
References#
These instructions were written for Telegraf
v1.25
Official Telegraf installation instructions:
https://docs.influxdata.com/telegraf/1.25/install/
Deployment Scripts#
An example bash script of the instructions has been provided:
deploy-telegraf.sh
Deployment Steps#
Note
Instructions assume execution using the root
account.
Add the InfluxDB Yum Repository:
# influxdb.key GPG Fingerprint: 05CE15085FC09D18E99EFB22684A14CF2582E0C5 cat > /etc/yum.repos.d/influxdb.repo <<EOF [influxdb] name = InfluxData Repository - Stable baseurl = https://repos.influxdata.com/stable/\$basearch/main enabled = 1 gpgcheck = 1 gpgkey = https://repos.influxdata.com/influxdata-archive_compat.key EOF
Install Telegraf:
dnf -y distro-sync dnf -y install telegraf
Create telegraf configuration file:
telegraf config \ --input-filter cpu:disk:diskio:kernel:mem:net:netstat:nfsclient:processes:smart:swap:system \ --output-filter influxdb_v2 \ --section-filter agent:inputs:outputs \ > telegraf.conf
Add the Influx API token to the telegraf user’s environment file:
Important
Replace
INFLUX_API_TOKEN
with the InfluxDB API Tokencat > /etc/default/telegraf <<EOF INFLUX_TOKEN=INFLUX_API_TOKEN EOF chmod 600 /etc/default/telegraf
Configure telegraf.conf file:
# Set InfluxDB server URL sed -i "s@urls = \[\"http://127.0.0.1:8086\"\]@urls = [\"${INFLUX_URL}\"]@g" telegraf.conf # Set InfluxDB token sed -i "s@token = \"\"@token = \"\${INFLUX_TOKEN}\"@g" telegraf.conf # Set organization sed -i "s@organization = \"\"@organization = \"${INFLUX_ORGANIZATION}\"@g" telegraf.conf # Set bucket sed -i "s@bucket = \"\"@bucket = \"${INFLUX_BUCKET}\"@g" telegraf.conf # Disable SSL cert verification sed -i "s@# insecure_skip_verify = false@insecure_skip_verify = true@g" telegraf.conf # Enable collecting of cpu_time sed -i "s@collect_cpu_time = false@collect_cpu_time = true@g" telegraf.conf # Enable nfs client full stats sed -i "s@## fullstat = false@fullstat = true@g" telegraf.conf # Setting 'use_sudo' to true will make use of sudo to run smartctl or nvme-cli. sed -i "s/# use_sudo = false/use_sudo = true/g" telegraf.conf # Setting Gather all returned S.M.A.R.T. attribute sed -i "s/# attributes = false/attributes = true/g" telegraf.conf
Copy telegraf.conf file:
mv -f telegraf.conf /etc/telegraf/telegraf.conf
Enable sudo access to smartctl for telegraf user:
cat > /etc/sudoers.d/telegraf <<EOF Cmnd_Alias SMARTCTL = /usr/sbin/smartctl telegraf ALL=(ALL) NOPASSWD: SMARTCTL Defaults!SMARTCTL !logfile, !syslog, !pam_session EOF
Enable telegraf service:
systemctl enable telegraf systemctl restart telegraf