Today we are on for a combination of Telegraf, InfluxDB and Grafana, and I want to get this to work because I am in preparation for a small IoT project of mine, and for simplicity sake I do not want to fiddle with the Raspberry,APIs and some MQTT set-up…I need to go step by step and I simply need an agent that would scrape my local machine statistics and send them on a dashboard. The part I am not sure of is the software piece in the middle between my source and my dashboard, namely here my time series database… And that’s how I came across these 3 applications. Let’s see… let’s get started.
First we start a couple of machines, and I choose in this occasion two Ubuntu 22 and we place them on the same LAN:
My Ubuntu image comes in with the correct VNC set-up so I just have to ssh once into it and run tigervncserver -localhost no -xstartup /usr/bin/gnome-session which is handy and now we are ready to login via my VNC client. Don’t forget to go into Settings > Power > Screen Blank – Never, in order to avoid getting locked out.
On instance 1 and 2, I decide to install telegraf for data collection, it is some sort of data collection data preparator for timeseries databases, anyway the link for telegraf is here https://docs.influxdata.com/telegraf/v1/install/. I simply install using apt install and we are good, but leave it as is for now, because we’ll come back to it later.
My instance 1 will host influxDB as well, instructions are here https://docs.influxdata.com/influxdb/v2/install/ install it, launch and enable it with systemctl start innodb.service. Log in at http://127.0.0.1:8086 and set-up some random values in there, just keep a note of these. Note that what InnoDB terminology calls a bucket what I understand is a “Database”, Grafana refers to the bucket as database which is confusing I know. Then go on “Load Data” and click Create Configuration, choose your bucket and “System”
Now there is a bug you will see a Telegraf configuration file it is almost empty… I think it should not be this way, just ignore and save changes. Click back on your configuration and you will see the telegraf.conf file ready for you; this telegraf.conf file is the file Telegraf needs to pull from when starting so it can point correctly to your InfluxDB.
Copy or download the file and remplace the /etc/telegraf/telegraf.conf file with it, don’t forget to do a cp /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.orig before just in case you mess it up! Then, the last thing you need to do is to edit In the environment variables file /etc/default/teleganf add the following which is the token telegraf will use to send its telemetry over to InfluxDB, like so:
And you do this on both instance of course… Don’t forget to lift the firewall on the main machine, in my case instance 1, at both local level with firewall-cmd (or other firewall utility depending on your Linux and image) and also turn off the firewall at the cloud platform level. So here we had to lift restrictions on port 8086/tcp. You should now see your data coming in nicely, and the correct dimensions e.g. instance-1 and instance-2 see below:
Finally, install grafana in my case also in my instance number 1 by following this link https://grafana.com/docs/grafana/latest/setup-grafana/installation/debian/ , you should pick your OS, once installed start the Grafana service and select connection, pick InfluxDB, and insert the http://ip:port combinaison required pointing to your DB, then fill your user name, database name (bucket name remember) and the token you have been using earlier… Now connection is established!
You can now navigate to your Grafana deployment and start building your queries, in the example below, I am looking at the memory usage per host.
And finally! We can enjoy some nice Grafana dashboards…
Ok and that’s it! I did struggle to figure out how the .conf files on the Telegraf side should be, even though retrospectively they require minimum modification…but whatever. I hope my article will help you in getting it to work quickly.