prometheus监控多个MySQL实例

摘要:
添加MySQL监控添加MySQL监控主机。以10.10.20.14为例#由于最新版本默认关闭了大量MySQL集合项,因此需要显式使用相应的选项来打开它们[root@localhost~]#cdmysqld_exporter[root@localhostmysqld_exporter]#nohup./mysqld_exporter-collect.info _ schema.processlist--collect.info _ chema.innodb _ tablespaces-collect.info=schema.innodb-metrics--collect.perf _ schema.tableiowaits-coollect.perf=schema.indexiowaits-Coollect.pperf _ schema.tablelocks-collect.info--collect.engine _ innodb_status-coollect.php _ schema.file _ events-collect.innfo _ schema.processlist--collect.binlog _ size--collect.info_schema.clientstats-collect.perf_架构。eventwaits##注意,新版本的mysqld_导出器可能不支持--collect.info _ schema.processlist选项,请自己使用/mysqld_exporter--help查看配置prometheusMySQL监视配置列表文件。由于主配置文件prometheus.yml定义了MySQL监控配置文件MySQL.yml,因此这里只需要填写主机IP信息即可使其动态有效。[ root@localhostmysqld_exporter]#cat/data/prometheus/mysql.yml标签:service:mysql_Testtargets:-10.10.30.165-10.10.20.14然后您可以在grafana页面上看到您配置的mysql实例。Web.listen-address表示这个mysqld_由prometheus调用的导出进程绑定的端口

添加MySQL监控

添加MySQL监控主机,这里以添加10.10.20.14为例进行说明。解压exporter压缩包。

[root@localhost ~]# tar xf mysqld_exporter-0.10.0.linux-amd64.tar 
[root@localhost ~]# mv mysqld_exporter-0.10.0.linux-amd64 mysqld_exporter

配置监控数据库需要的主机IP、数据库端口、数据库账号和密码的环境变量。

[root@luoxiaobo-01 ~]# export DATA_SOURCE_NAME='admin:letsg0@(10.10.20.14:3306)/'
[root@luoxiaobo-01 ~]# echo "export DATA_SOURCE_NAME='admin:letsg0@(10.10.20.14:3306)/'" >> /etc/profile

启动exporter。

# 由于目前最新的版本默认关闭了大量的mysql采集项,需要显式使用相应的选项开启(截止到写稿时间,最新的开发版本可以通过prometheus端的配置项让exporter端生效,而无需再exporter中使用大量的启动选项开启)
[root@localhost ~]# cd mysqld_exporter
[root@localhost mysqld_exporter]# nohup ./mysqld_exporter --collect.info_schema.processlist --collect.info_schema.innodb_tablespaces --collect.info_schema.innodb_metrics  --collect.perf_schema.tableiowaits --collect.perf_schema.indexiowaits --collect.perf_schema.tablelocks --collect.engine_innodb_status --collect.perf_schema.file_events --collect.info_schema.processlist --collect.binlog_size --collect.info_schema.clientstats --collect.perf_schema.eventswaits &
# 注意,新版本的mysqld_exporter可能不支持--collect.info_schema.processlist 选项,请自行使用./mysqld_exporter --help查看

配置prometheus MySQL监控配置列表文件,由于之前主配置文件prometheus.yml 中已经定义了监控MySQL的配置文件mysql.yml,这里只需要把主机IP信息填入即可动态生效。

[root@localhost mysqld_exporter]# cat /data/prometheus/mysql.yml
- labels:
service: mysql_test
  targets:
  - 10.10.30.165
  - 10.10.20.14

然后,在grafana页面中就可以看到你配置的MySQL实例 。

prometheus监控多个MySQL实例第1张

  这种方式是在每个mysql服务器上跑一个exporter程序,比如10.10.20.14服务器上跑自己的exporter,然后再到登到10.10.30.165服务器上启动自己的exporter,也就是分离部署,这样的话每个mysql服务器上除了mysqld进程外还会多一个mysqld_exporter的进程。但是如果我们想要保持mysql服务器零入侵的纯净环境,应该怎么办呢,这时候我们就可以尝试一下集中部署+配置文件的方式。

mysqld_exporter集中部署

集中部署,就是说我们将所有的mysqld_exporter部署在同一台服务器上,在这台服务器上对mysqld_exporter进行统一的管理,下面介绍一下集中部署的方法。这里我们专门起一台IP为172.18.0.23的服务器,另外两台172.18.0.11和172.18.0.13作为2个MySQL节点。

prometheus监控多个MySQL实例第2张

  在172.18.0.23上下载安装mysqld_exporter

添加172.18.0.11节点

1、在172.18.0.11上建立监控用户

GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@'%' IDENTIFIED BY 'pmm';

2、在172.18.0.23上编辑172.18.0.11节点的配置文件

[root@mysqld_exporter-23 /]# cd /data/mysqld_exporter/
[root@mysqld_exporter-23 mysqld_exporter]# cat etc/.dk-11.cnf
[client]
user=pmm
password=pmm
host=172.18.0.11
port=3306

3、在172.18.0.23上启动mysqld_exporter

[root@mysqld_exporter-23 ~]# cd /data/mysqld_exporter/
[root@mysqld_exporter-23 mysqld_exporter]# nohup ./mysqld_exporter --web.listen-address=172.18.0.23:9104 --config.my-cnf=etc/.dk-11.cnf --collect.auto_increment.columns --collect.binlog_size --collect.global_status --collect.global_variables --collect.info_schema.innodb_metrics --collect.info_schema.innodb_cmp --collect.info_schema.innodb_cmpmem --collect.info_schema.processlist --collect.info_schema.query_response_time --collect.info_schema.tables --collect.info_schema.tablestats --collect.info_schema.userstats --collect.perf_schema.eventswaits --collect.perf_schema.file_events --collect.perf_schema.indexiowaits --collect.perf_schema.tableiowaits --collect.perf_schema.tablelocks --collect.slave_status &

这里看到mysqld_exporter的启动多了两个选项,"--web.listen-address"和"--config.my-cnf"。

web.listen-address代表这个mysqld_exporter进程绑定的端口,以供prometheus调用,这里暴露的是172.18.0.23的9104端口。

config.my-cnf代表这个mysqld_exporter进程监控的MySQL的连接信息。

4、在prometheus服务器配置prometheus文件

[root@prometheus-21 /]# cd /data/prometheus/
[root@prometheus-21 prometheus]# cat prometheus.yml
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
  - file_sd_configs:
    - files:
      - mysql.yml
    job_name: MySQL
    metrics_path: /metrics
    relabel_configs:
    - source_labels: [__address__]
      regex: (.*)
      target_label: __address__
      replacement: $1

5、在prometheus服务器配置mysql.yml文件

 [root@prometheus-21 prometheus]# cat mysql.yml
- labels:
    instance: dk-11:3306 # grafana显示的实例的别名
  targets:
  - 172.18.0.23:9104 # mysqld_exporter暴露的端口

mysql.yml的172.18.0.23:9104会通过prometheus配置文件中的file_sd_configs配置,作为变量传给$1,然后替换__address__,因而被prometheus所识别。

6、使prometheus配置生效

[root@prometheus-21 prometheus]# pgrep -fl prometheus
33 /data/prometheus/prometheus --storage.tsdb.retention=30d
[root@prometheus-21 prometheus]# kill -HUP 33

7、验证172.18.0.11是否添加成功

浏览器输入Prometheus_IP:9090

prometheus监控多个MySQL实例第3张

  浏览器输入Grafana_IP:3000

prometheus监控多个MySQL实例第4张

  添加172.18.0.13节点

1、在172.18.0.13上建立监控用户

GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@'%' IDENTIFIED BY 'pmm';

2、在172.18.0.23上编辑172.18.0.13节点的配置文件

[root@mysqld_exporter-23 /]# cd /data/mysqld_exporter/
[root@mysqld_exporter-23 mysqld_exporter]# cat etc/.dk-13.cnf
[client]
user=pmm
password=pmm
host=172.18.0.13
port=3306

3、在172.18.0.23上启动mysqld_exporter

[root@mysqld_exporter-23 ~]# cd /data/mysqld_exporter/
[root@mysqld_exporter-23 mysqld_exporter]# nohup ./mysqld_exporter --web.listen-address=172.18.0.23:9105 --config.my-cnf=etc/.dk-13.cnf --collect.auto_increment.columns --collect.binlog_size --collect.global_status --collect.global_variables --collect.info_schema.innodb_metrics --collect.info_schema.innodb_cmp --collect.info_schema.innodb_cmpmem --collect.info_schema.processlist --collect.info_schema.query_response_time --collect.info_schema.tables --collect.info_schema.tablestats --collect.info_schema.userstats --collect.perf_schema.eventswaits --collect.perf_schema.file_events --collect.perf_schema.indexiowaits --collect.perf_schema.tableiowaits --collect.perf_schema.tablelocks --collect.slave_status &
这里暴露的是9105端口,使用的是.dk-13.cnf的文件。

4、在prometheus服务器配置mysql.yml文件

[root@prometheus-21 prometheus]# cat mysql.yml
- labels:
    instance: dk-11:3306
  targets:
  - 172.18.0.23:9104
- labels:
    instance: dk-13:3306
  targets:
  - 172.18.0.23:9105

只需要添加172.18.0.13的mysqld_exporter对应的端口和别名就可以。

5、验证172.18.0.13是否添加成功

浏览器输入Prometheus_IP:9090

prometheus监控多个MySQL实例第5张

 浏览器输入Grafana_IP:3000 

prometheus监控多个MySQL实例第6张

集中管理

当我们需要添加新的节点,只需要将新节点的连接信息配置好,划分新的端口,启动mysqld_exporter,然后在prometheus中的mysql.yml文件添加新节点暴露的端口以及新节点的自定义别名就可以了。

这样我们就可以在mysqld_exporter节点上对mysqld_exporter的进程进行统一管理了。

prometheus监控多个MySQL实例第7张

 转载自:https://zhuanlan.zhihu.com/p/77020680

免责声明:文章转载自《prometheus监控多个MySQL实例》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇从U盘安装centos7.6(史上最简单的终极解决方案)X ORACLE19c的RAC集群部署-详细完整篇下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

mariadb5.5.56二进制离线安装

在生产环境中一般使用发布好的二进制版本,简单概括一下安装过程:   1. 下载 地址为:https://downloads.mariadb.org/mariadb/5.5.56/   这里选择最新版本的5.5.56稳定版,进入后根据计算机位数选择,这里下载适用于64位操作系统的Linux x86_64版本   这里下载包含glibc和不包含glibc的都是...

mac 设置 MySQL 数据库默认编码(字符集)为 UTF-8

mac 设置 MySQL 数据库默认编码(字符集)为 UTF-8 原文链接:https://juejin.im/post/5bbdca76e51d45021147de44 鉴于有些刚接触 MySQL 数据库的人,经常会碰到数据库中文显示的问题,MySQL 数据库刚安装时默认编码是 latin1,所以如果在数据库建表的时候没有设置 DEF...

MYSQL常用命令集合(转载)

文章出处:http://www.cnblogs.com/q1ng/p/4474501.html 1.导出整个数据库mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1)mysqldump -u wcnc -p smgp_apps_wcnc >...

linux开启MySql远程连接功能

MySql默认只有本机(127.0.0.1)能够访问,要开启主要有两步骤:配置MySql绑定IP和建立允许远程访问的账户。 一、修改IP绑定 需要修改MySql的配置文件my.cnf 如果你使用Debian Linux,文件位置在: /etc/mysql/my.cnf 如果你使用Red Hat Linux/Fedora/Centos Linux,文件位置...

MySQL配置文件改变了datadir值

从Noinstall Zip Archive中安装MySQL正在从Noinstall软件包安装MySQL的用户可以使用这个说明来手动安装MySQL。从Zip archive 中安装MySQL的 步骤如下: 1 在指定的安装目录下解压软件包。 2 制造选择文件。 3 选择MySQL服务类型。 4 开始MySQL服务。 5 保护默认...

MySQL update慢问题解决 规格严格

最近新做的一个项目要发布,结果在最终测试时候出问题了。后台的MySQL一直CPU使用率居高不行,通过: show processlist查看到一个SQL很异常,update XX set YY = KK where pK = ?; 这是一个简单的SQL,可是为什么他可能会影响问题呢。 背景: MySQL数据库,MyIsam表,按照时间建立一级分区,按照天建...