MariaDB/MySQL Monitoring, Telegraf installation. Part 1

MariaDB/MySQL Monitoring, Telegraf installation. Part 1

Colleagues hello to all.

In today's article, we'll talk about how to install the Telegraf client on a MariaDB database server to pass metrics to InfluxDB. In addition, we will prepare the InfluxDB database to receive metrics from Telegraf.

 

Servers I will use:

  • 192.168.2.225 - Server where I have Grafana and InfluxDB installed.
  • 192.168.2.227 - Server where my DBMS MariaDB. 

 

Article content:

  1. InfluxDB create database.
  2. InfluxDB user creation.
  3. Installing Telegraf on the MariaDB server.
  4. Configuring Telegraf to send metrics to InfluxDB.
  5. Total

 

1. InfluxDB database creation.

And so, before installing the Telegraf client itself on the MariaDB database server, let's first create a database in InfluxDB.

 

1.1. Connecting to the influxdb console.

$. influx -username admin -password 'Qwerty123';

monitoring_mariadb

 

1.2. Let's create a database for metrics called mariadb. In this database we will store our metrics that will come from Telegraf.

influx> CREATE DATABASE mariadb;

monitoring_mariadb

 

1.3. Let's create a retention policy for our data. I want my data to be kept for 30 days. After 30 days, the old data will be automatically deleted from the InfluxDB database.

influxdb> CREATE RETENTION POLICY "mariadb_retention_policy" ON "mariadb" DURATION 3w REPLICATION 1 DEFAULT;

monitoring_mariadb


 

2. InfluxDB user creation.

After creating a database for metrics, we need to create an account under which Telegraf and Grafana will be authorized.

 

2.1. Create an account in InfluxDB.

influx> CREATE USER mariadb_client WITH PASSWORD 'Qwerty123';

monitoring_mariadb

 

2.2. Now let's set the privileges of our account so that we can read and write to the database.

influx> GRANT ALL ON "mariadb" TO "mariadb_client";

monitoring_mariadb


 

3. Installing Telegraf on a MariaDB server.

Once we've prepared the InfluxDB database to receive metrics, we can now install Telegraf itself on the MariaDB server.

 

3.1. First, let's prepare a repository for installing Telegraf. We need to create the influxdata.repo file in the /etc/yum.repos.d directory.

$. vim /etc/yum.repos.d/influxdata.repo

and paste into it:

[influxdata]
name = InfluxData Repository - Stable
baseurl = https://repos.influxdata.com/stable/\$basearch/main
enabled = 1
gpgcheck = 1
gpgkey=https://repos.influxdata.com/influxdb.key

monitoring_mariadb

 

3.2. Launching the Telegraf installation.

$. sudo yum install telegraf

monitoring_mariadb

Done, Telegraf installed successfully.


 

4. Configuring Telegraf to send metrics to InfluxDB.

The Telegraf client can send a variety of metrics to the InfluxDB database, you can see the full list of parameters here:

https://github.com/influxdata/telegraf/blob/release-1.22/plugins/inputs/mysql/README.md

 

4.1. Setting up a connection to InfluxDB.

The main file with settings in Telegraf is called telegraf.conf which is located in the /etc/telegraf directory. And with the help of it we will configure connections to InfluxDB.

 

4.1.1. Open the  telegraf.conf file.

$. vim /etc/telegraf/telegraf.conf

 

4.1.2. Find [[outputs.influxdb]].

monitoring_mariadb

 

4.1.3. Editing the parameters.

  • urls - Address where we installed InfluxDB itself
  • database - The name of the database we created in InfluxDB
  • username - The database account name we created in InfluxDB
  • password - The password for the account which we created in InfluxDB

monitoring_mariadb

You should get the same result as mine.

 

4.1.4. Check.

$. service telegraph status

monitoring_mariadb

monitoring_mariadb

Everything works. As we can already see, our Telegraf transfers data to InfluxDB, but this data has nothing to do with MariaDB itself yet.

 

4.2. Now let's make it so that the data is transferred not only from the server itself, but also through the database.

 

4.2.1. Let's create an additional file called mariadb.conf in the /etc/telegraf/telegraf.d directory, you can think of any name for the file.

$. vim /etc/telegraf/telegraf.d/mariadb.conf

 

4.2.2. Let's add parameters related to the database connection to the file.

[[inputs.mysql]]
  servers = ["tcp(127.0.0.1:3306)/"]
  metric_version = 2

  table_schema_databases = []
  gather_table_schema = true

monitoring_mariadb

Save and restart Telegraf.

 

4.2.3. Checking.

monitoring_mariadb

As you can see, another table associated with mariadb has been added to the InfluxDB database, which means we did everything right.


 

5. Total.

As a result, today we successfully installed the Telegraf client on the MariaDB database server. In the next article, I will show you how to add an InfluxDB data source to Grafana.

SIMILAR ARTICLES

InfluxDB authentication and authorization
InfluxDB authentication and authorization
MONITORING
Read more
InfluxDB how to create a database
InfluxDB how to create a database
MONITORING
Read more
Installing Influxdb on Centos 8
Installing Influxdb on Centos 8
MONITORING
Read more