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

在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
prometheus.yml文件更改后需要上述操作后生效,mysql.yml修改后prometheus会自动识别。
7、验证172.18.0.11是否添加成功
浏览器输入Prometheus_IP:9090
浏览器输入Grafana_IP:3000
添加172.18.0.13节点
添加新的节点到监控,只需要做4步就可以。
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
浏览器输入Grafana_IP:3000
集中管理
当我们需要添加新的节点,只需要将新节点的连接信息配置好,划分新的端口,启动mysqld_exporter,然后在prometheus中的mysql.yml文件添加新节点暴露的端口以及新节点的自定义别名就可以了。
这样我们就可以在mysqld_exporter节点上对mysqld_exporter的进程进行统一管理了。
改造
文章地址:https://www.cnblogs.com/sanduzxcvbnm/p/13094580.html
根据这篇文章的讲述,可以稍加改造,使用多个mysqld_exporter.service服务,名称区分开,比如mysqld_exporter1.service,mysqld_exporter2.service等,在每个里面配置上数据库的连接信息
7.prometheus监控多个MySQL实例的更多相关文章
- k8s中prometheus监控k8s外mysql
k8s外安装mysql https://www.cnblogs.com/uncleyong/p/10739530.html 配置MySQL Exporter采集MySQL监控数据 创建yaml文件:v ...
- 使用 Docker 部署 Grafana + Prometheus 监控 MySQL 数据库
一.背景 在平时开发过程当中需要针对 MySQL 数据库进行监控,这里我们可以使用 Grafana 和 Prometheus 来实现监控功能.Grafana 是一款功能强大的仪表盘面板,支持多种数据源 ...
- Docker监控平台prometheus和grafana,监控redis,mysql,docker,服务器信息
Docker监控平台prometheus和grafana,监控redis,mysql,docker,服务器信息 一.通过redis_exporter监控redis 1.1 下载镜像 1.2 运行服务 ...
- [k8s]prometheus+grafana监控node和mysql(普罗/grafana均vm安装)
https://github.com/prometheus/prometheus Architecture overview Prometheus Server Prometheus Server 负 ...
- Grafana+Prometheus 监控 MySQL
转自:Grafana+Prometheus 监控 MySQL 架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.lin ...
- Prometheus 监控Mysql服务器及Grafana可视化
Prometheus 监控Mysql服务器及Grafana可视化. mysql_exporter:用于收集MySQL性能信息. 使用版本 mysqld_exporter 0.11.0 官方地址 使用文 ...
- 手把手教你使用 Prometheus 监控 MySQL 与 MariaDB.md
概述 MySQL 是常用的关系型数据库,MariaDB 作为 MySQL 的分支版本,兼容 MySQL 协议,也越来越流行.在 Kubernetes 环境中如何使用 Prometheus 来对它们进行 ...
- Kubernetes容器集群管理环境 - Prometheus监控篇
一.Prometheus介绍之前已经详细介绍了Kubernetes集群部署篇,今天这里重点说下Kubernetes监控方案-Prometheus+Grafana.Prometheus(普罗米修斯)是一 ...
- 使用Prometheus监控SpringBoot应用
通过之前的文章我们使用Prometheus监控了应用服务器node_exporter,数据库mysqld_exporter,今天我们来监控一下你的应用.(本文以SpringBoot 2.1.9.REL ...
随机推荐
- Python进程管理神器——Supervisor
一.简介 Supervisor 是一款 Python 开发的进程管理系统,允许用户监视和控制 Linux 上的进程,能将一个普通命令行进程变为后台守护进程,异常退出时能自动重启 详细介绍查阅:Supe ...
- 类型转换_str()函数与int()函数
数据类型转换 需要将不同数据类型拼接在一起的时候就需要先进行数据类型转换 str+str//这里的+叫做连接字符,有点类似C++中的操作符重载,老对象里面的内容了 在python中整型和字符串类型不能 ...
- 0202年,您真的需要Thrift这样一个RPC微服务框架来拯救一下传统HTTP接口(api)了
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_104 目前市面上类似Django的drf框架基于json的http接口解决方案大行其道,人们也热衷于在接口不多.系统与系统交互较少 ...
- 奇技淫巧玄妙无穷| M1 mac os(苹果/AppleSilicon)系统的基本操作和设置
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_191 最近有个朋友跟我说,说他新入职了一家公司,公司还不错,给他配了一台Mac,但是呢他以前一直在Windows环境下开发,对Ma ...
- JAVA语言基础组成(1)
JAVA语言基础组成 关键字 关键字的定义和特点 定义:被Java语言赋予了特殊含义的单词 特点:关键字中所有字母都为小写 用于定义数据类型的关键字 class interface byte int ...
- 从贡献第一个 pr 开始,我的开源之路正式开启
点击上方蓝字关注我们 1 我是一名开源爱好者 我是李进勇,Github Id:JinyLeeChina,目前就职于政采云,专注于大数据平台及数仓领域,是开源项目爱好者. 2 我与小海豚的不解之缘 记得 ...
- Apache DolphinScheduler使用规范与使用技巧分享
本次分享来源2021年9月4日杨佳豪同学,给大家带来的分享是基于 Apache DolphinScheduler 使用规范与使用技巧分享,分享的内容主要为以下五点: " DolphinSch ...
- Apache DolphinScheduler 使用文档(5/8):使用与测试
本文章经授权转载,原文链接: https://blog.csdn.net/MiaoSO/article/details/104770720 目录 5. 使用与测试 5.1 安全中心(Security) ...
- HTTP/3,它来了
HTTP 3.0 是 HTTP 协议的第三个主要版本,前两个分别是 HTTP 1.0 和 HTTP 2.0 ,但其实 HTTP 1.1 我认为才是真正的 HTTP 1.0. 如果你对 HTTP 1.1 ...
- 052_末晨曦Vue技术_处理边界情况之程序化的事件侦听器
程序化的事件侦听器 点击打开视频讲解更详细 现在,你已经知道了 $emit 的用法,它可以被 v-on 侦听,但是 Vue 实例同时在其事件接口中提供了其它的方法.我们可以: 通过 $on(event ...