Install Telegraf and configure for InfluxDB
Video Lecture
Description
Now to install the Telegraf agent and configure the output plugin to save data into the InfluxDB2.
The installation commands for your OS are at https://portal.influxdata.com/downloads/
For these instructions, I have chosen Telegraf v1.20.4
version and the Ubuntu & Debian
platform.
Download the package.
wget https://dl.influxdata.com/telegraf/releases/telegraf_1.20.4-1_amd64.deb
Install it using the package manager.
sudo dpkg -i telegraf_1.20.4-1_amd64.deb
It is normally started by default. We can check its status.
sudo service telegraf status
If it isn't started, then you can start it.
sudo service telegraf start
CD into the new Telegraf folder
cd /etc/telegraf
Create a backup of the existing Telegraf config.
cp telegraf.conf telegraf.conf.bak
Delete the telegraf.conf
rm telegraf.conf
Create a new telegraf.conf
sudo nano telegraf.conf
Paste this minimal configuration text into it.
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false
[[outputs.influxdb_v2]]
urls = ["http://127.0.0.1:8086"]
token = "YOUR TELEGRAF READ/WRITE TOKEN"
organization = "YOUR ORG NAME"
bucket = "telegraf"
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
Replace "YOUR TELEGRAF READ/WRITE TOKEN" above with the token created using the technique as shown in the video.
Replace "YOUR ORG NAME" with the organization that you created earlier.
Restart Telegraf and check it's status.
sudo service telegraf restart
sudo service telegraf status
InfluxDB should now be able to query some extra metrics and you should be able to also query them in Grafana as demonstrated in the video.
Example flux query
from(bucket: "telegraf")
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "cpu"
and r._field == "usage_user"
)
Useful Links
Grafana 9 and Ubuntu 22.04 Notes
There are no considerable differences to be aware of as shown and discussed in the video.
InfluxDB 2.4.0
When recreating the System dashboard from InfluxDB into Grafana, it is no longer necessary to replace the v.bucket
text from the original flux queries with "telegraf"
. But you can continue to do so if you wish.