Home  >  Article  >  Database  >  How to configure mysql monitoring for prometheus service monitoring

How to configure mysql monitoring for prometheus service monitoring

王林
王林forward
2023-06-02 12:43:062090browse

prometheus service monitoring mysql monitoring


If your machine has not installed prometheus, please refer to the following installation steps:

Part 1: Introduction and installation of prometheus

After becoming familiar with the above two parts, we enter today's service monitoring, taking mariadb as an example:

To monitor mysql, you need to install mysql_exporter on the monitored machine

1 .Upload, decompress and install mysqld_exporter

  root@xinsz08-20 ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz   文件名字太长,重命名一下:   [root@xinsz08-20 ~]# mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter   [root@xinsz08-20 ~]# cd mysqld_exporter/   [root@xinsz08-20 mysqld_exporter]# pwd   /root/mysqld_exporter

2. Install mariadb

   root@xinsz08-20 mysqld_exporter]# yum install mariadb\* -y   [root@xinsz08-20 ~]# systemctl start mariadb   [root@xinsz08-20 ~]# systemctl enable  mariadb   [root@xinsz08-20 ~]# ss -natlp |grep 3306   //查看端口是否开启   LISTEN   0         80                  0.0.0.0:3306             0.0.0.0:*        users:(("mysqld",pid=67872,fd=22))

3. Create a mysql account user in the database to collect data

[root@xinsz08-20 ~]# mysql      MariaDB [(none)]> grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by '12345678';   Query OK, 0 rows affected (0.000 sec)      MariaDB [(none)]> flush privileges;   Query OK, 0 rows affected (0.000 sec)      MariaDB [(none)]> exit   Bye

#Note: Here the prometheus server is looking for mysql_exporter, and then mysql_exporter is looking for mariadb, so localhost is used here, which refers to the ip of mysql_exporter

4. In mysql_exporter Set mysql configuration information in

 [root@xinsz08-20 mysqld_exporter]# pwd   /root/mysqld_exporter      [root@xinsz08-20 mysqld_exporter]# vim .my.cnf  (手工创建)      [client]   user=mysql_monitor   password=12345678

5. Start mysql_exporter

 [root@xinsz08-20 mysqld_exporter]# nohup ./mysqld_exporter --config.my   -cnf=/root/mysqld_exporter/.my.cnf &   [1] 68166

6. Configure prometheus to pull mysql node information

 [root@zmedu-17 prometheus-2.16.0.linux-amd64]# pwd   /root/prometheus-2.16.0.linux-amd64   [root@zmedu-17 prometheus-2.16.0.linux-amd64]# vim prometheus.yml    - job_name: 'mariadb'       static_configs:       - targets: ['192.168.1.20:9104']

#Make changes on the server side of prometheus

Restart the prometheus service

[root@zmedu-17 prometheus-2.16.0.linux-amd64]# pkill prometheus   [root@zmedu-17 prometheus-2.16.0.linux-amd64]# lsof -i:9090   [root@zmedu-17 prometheus-2.16.0.linux-amd64]# ./prometheus &   [1] 84662   [root@zmedu-17 ~]# ss -naltp |grep 9090   LISTEN     0      128       [::]:9090                  [::]:*                   users:(("prometheus",pid=84662,fd=9))

7. View through the web side

http://192.168.1.17:9090

How to configure mysql monitoring for prometheus service monitoring

Check the number of mysql connections and see There is only one connection number:

mysql_global_status_aria_pagecache_blocks_unused

How to configure mysql monitoring for prometheus service monitoring

##8. Detailed explanation of prometheus.yml configuration file

global:   # 全局配置     scrape_interval:     15s # 多久收集一次数据        evaluation_interval: 15s # 多久评估一次规则     scrape_timeout:10s  # 每次收集数据的超时时间   # Alertmanager configuration #告警设置   alerting:     alertmanagers:     - static_configs:  #告警规则,也可以基于动态方式进行告警       - targets:   rule_files:  #规则文件   #收集数据配置列表   scrape_configs:     - job_name: 'prometheus'

9. English translation of prometheusUI

How to configure mysql monitoring for prometheus service monitoring

##Alerts: means that we can see the alarm rules we defined Graph: means The interface queries data, generates pictures, or returns data. Status: The following target: represents our remote monitoring. You can see the operation of the exporter

The above is the detailed content of How to configure mysql monitoring for prometheus service monitoring. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete