Telegraf is an plugin-based agent written in GO programming language for collecting metrics from local and remote sources and writes the output to multiple resources at the same time. The metrics and events can be from databases, IoT sensors, third-party APIs and host systems.

The features of Telegraf include:

  • No external dependencies
  • Minimal memory footprint.
  • Wide number of plugins include; Input, output and service plugins.

In this guide, I will show you how to :

  • Install Telegraf using PowerShell on Windows 11 / Windows 10
  • Use Telegraf with InfluxDB on Windows 11 / Windows 10

Setup Pre-requisites

Ensure you have InfluxDB setup on your machine. If not use InfluxDB Setup guide available on our website to install InfluxDB.

Install Telegraf on Windows 11 / Windows 10

Go to InfluxData downloads to get the command to install Telegraf. Scroll down to the Telegraf section and select Windows Binaries from the dropdown menu.

Select the latest version of Telegraf available and choose Windows Binaries under Platform.

Copy the commands generated and paste in your terminal. Example;

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.23.0_windows_amd64.zip -UseBasicParsing -OutFile telegraf-1.23.0_windows_amd64.zip
Expand-Archive .\telegraf-1.23.0_windows_amd64.zip -DestinationPath 'C:\Program Files\InfluxData\telegraf'

Open PowerShell as an administrator and paste the command to install and extract the zip file to the destination C:\Program Files\InfluxData\telegraf path.

The download starts immediately and should take short time period.

The files are extracted to the said path as shown below. Move the telegraf.exe and telegraf.conf files from C:\Program Files\InfluxData\telegraf\telegraf-1.23.0 up a level to C:\Program Files\InfluxData\telegraf:

 cd "C:\Program Files\InfluxData\telegraf"
 mv .\telegraf-1.23.0\telegraf.* .

Configuring Telegraf on Windows using telegraf.conf file.

Open the Config file and go to Output Plugins Section.

The details are in default as shown above. If you would desire to change details like the token, host-url and organization name. This is where you will change it.

Run Telegraf as a Service on Windows 11 / Windows 10

Next up is to set Telegraf to run a service in Windows so that it starts automatically with the system and can collect metrics in real-time.

Open Windows PowerShell as an administrator and change the directory to the Telegraf folder.

cd 'C:\Program Files\InfluxData\telegraf'

Next up is to install the service.

.\telegraf.exe --service install --config "C:\Program Files\InfluxData\telegraf\telegraf.conf"

To test if the installation worked, use:

C:\"Program Files"\InfluxData\telegraf\telegraf.exe --config C:\"Program Files"\InfluxData\telegraf\telegraf.conf --test

See screenshot below:

Then start the service with

.\telegraf.exe --service start

Collecting Metrics with Telegraf on Windows

Ensure that influxd server is running and head over to localhost:8086. Login with your credentials. Go to Data>Buckets>Create Bucket

Once you create it appears in the list under buckets as shown below.

Then go to Data>Telegraf>Create Configuration.

It opens the window to select the bucket where the data will be stored, Choose telegraf from the dropdown menu. Click Continue.

Then create a name and description for the telegraf configuration. Click Create and Verify.

You will get impromptu dialogs that a token has been created and saved.

Before you click Listen to Data or Finish, Go to your Windows PowerShell and change the directory as follows.

cd "C:\Program Files\InfluxData\telegraf"

Then export the token by using

$env:INFLUX_TOKEN = "YourAuthenticationToken"

Next will be to run telegraf using the code

.\telegraf --config http://localhost:8086/api/v2/telegrafs/08cc56eb251d2000

Go back to the InfluxDB Telegraf configuration and click Listen to Data. It will show ‘Connection Found‘ if it is sending data then click on Finish.

Go to Explore and select the telegraf bucket, You will now see that the measurements come up and you can filter to view what you like.

You can also change how you view the data. Like I changed to Gauge and it appeared as follows

Conclusion

Telegraf is a plugin that makes it simple to collect metrics from your system or any other source that you want and output the events to multiple sources also like InfluxDB. It is simple to use and requires no external dependencies to function which makes it faster to configure and establish a connection.

More article to read through:

LEAVE A REPLY

Please enter your comment!
Please enter your name here