Skip to content
Category: SQL Server
2020-06-23

Free monitoring using InfluxDB, Telegraf and Grafana

In this serie of monitorization that i will start today, we are going to see through various posts how to create a free and interactive monitoring system.

The first post will deal with one of the most important tasks, which is the configuration and installation of Telegraf to collect the data from the counters that will be sent to our InfluxDB database and then display them using Grafana.

What is Telegraf, InfluxDB and Grafana?

Telegraf is a very light agent that is in charge of collecting, processing and sending the metrics of a machine that we want to monitor to our database, Influxdb.

InfluxDB is the database in which we will store the metrics sent from the agent. This database is designed to withstand high write and read loads. Here is some more information.

Grafana is a data analysis platform that allows viewing it using queries. We can create panels that show only X data.

Previous Requirements

Before starting the post we must have a previous scenario to be able to use this agent. We will use two servers that we will call Server1 and Server2:

  • Server1 with InfluxDB and Grafana installed. We have used a Linux server. Here you can see how to install InfluxDB and Grafana
    We must open the output port 3000, it is the one that Grafana uses and enable the input port that InfluxDB uses. The default port is 8086
  • Server2: A machine that we want to monitor, in our case it will be Windows. With the output port that we have enabled for Influxdb open. 8086 if it is the default port.

Once we have these steps we will go on to explain the installation and configuration of the Telegraf file and its operation.

To start monitoring we must perform two tasks

  1. Create the Database with InfluxDB
  2. Configure and install Telegraf

Create the Database with InfluxDB

Before starting with the configuration we need to create a database to store the server metrics that we want to monitor, so the first step will be to access Server1 where we have InfluxDB installed.

Inside the machine we access InfluxDB using the following command:

influx -host localhost -port 8086

-port: Here we will put the port which we have configured our database. 8086 is the default port.

Ahora crearemos la nueva base de datos donde se conectará Telegraf:

CREATE DATABASE AlesonITC WITH DURATION 30d

DURATION: Time that we want to store the data of the monitored server. In this case it will be 30 days

To show all databases we use:

SHOW ALL DATABASES

We already have the database created, now we can go to configure and install Telegraf.

Configure and Install Telegraf

On Server2, Windows. Open the browser and download the Telegraf files for InfluxDB from Github.

Once downloaded unzip the files. Copy the file telegraf.conf.sample and rename it to telegraf.conf. When we have renamed it, open it and go to configure the file.

First we must configure the time it takes to collect the data and send it:

By default it is 10 seconds, but depending on the number of servers this can be a problem so we have increased it to 1 minute.

The next step will be to configure the IP of Server1, our InfluxDB server, with its respective port:

Add the database that we just created:

Next step, we can choose the metrics that we want to be collected and sent. We have only selected Windows, but there are many plugins that you can see at the following link, Plugins.

To add the plugin, copy the code and paste it at the end of the telegraf.conf file.

Once the configuration of the file is done, proceed with the installation of the agent.

Open a file explorer, access “C: \ Program files” and create a folder called telegraf to store the files telegraf.exe and telegraf.conf

Move the files telegraf.exe y telegraf.conf to this folder and open a command line as administrator.

Move to this folder:

cd “c:\program files\telegraf”

Install the agent:

telegraf.exe --service install

Start the service:

net start telegraf

To see if there is any error we open telegraf.exe with the command line:

Go back to Server1 and go back to InfluxDB to check that the data is coming:

influx -host localhost -port 8086

Select the Database that we are using to storage the metrics:

use AlesonITC

To verify that you are receiving data, we will launch a query with the data that the Telegraf Agent is sending:

select Percent_User_Time from win_cpu

As we can see the query shows us the data that is being stored within this database.

In the next post we will teach you how to use Grafana to visualize the data in a useful and accurate way.

You can’t miss it!

If you want us to help your business or company contact us at info@aleson-itc.com or call us at +34 962 681 242.