当前位置:网站首页>【夜莺监控方案】08-监控msyql集群(prometheuse+n9e+mysqld_exporter)
【夜莺监控方案】08-监控msyql集群(prometheuse+n9e+mysqld_exporter)
2022-08-03 18:57:00 【开发运维玄德公】
文章目录
1. 安装mysqld_exporter
- 创建
mysqld_exporter目录 - 在
mysqld_exporter目录下创建docker-compose.yml文件
version: '3.3'
services:
mysql_exporter_hq_m:
image: harbocto.xxx.com.cn/bdteam/mysqld-exporter:latest
container_name: mysql_exporter_hq_m
ports:
- 9104:9104
restart: always
environment:
DATA_SOURCE_NAME: "数据库用户:密码@(IP:端口)/"
mysql_exporter_hq_s:
image: harbocto.xxx.com.cn/bdteam/mysqld-exporter:latest
container_name: mysql_exporter_hq_s
ports:
- 9105:9104
restart: always
environment:
DATA_SOURCE_NAME: "数据库用户:密码@(IP:端口)/"
- 启动
docker-compose up -d
- 查看结果
[[email protected] mysql_exporter]# docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------
mysql_exporter_hq_m /bin/mysql_exporter_hq_m Up 0.0.0.0:9104->9104/tcp
mysql_exporter_hq_m /bin/mysql_exporter_hq_m Up 0.0.0.0:9105->9104/tcp
- web页面查看结果
访问 http://IP:9104/metric 可以看倒获取的mysql信息。
2. 配置prometheus
- 修改
prometheus.yml文件,添加如下内容:
- job_name: 'HQAllInOnePC'
scrape_interval: 15s
static_configs:
- targets: ['10.10.xxx.64:9104','10.10.xxx.64:9105']
params:
collect[]:
- global_status
- perf_schema.tableiowaits
- perf_schema.indexiowaits
- perf_schema.tablelocks
- slave_status
- slave_hosts
- 重启服务
- 访问prometheuse的targets查看结果如下:

3. 配置n9e 图表
3.1 手动配置(方法一)
参考《04-监控redis集群-prometheuse+n9e》中“3.2 配置图表"
3.2 导入模板(方法二)

模板内容如下:
[
{
"id": 0,
"name": "mysql监控",
"tags": "",
"configs": "{\"tags\":[{\"tagName\":\"job\",\"key\":\"job\",\"value\":\"HQAllInOnePC\",\"prefix\":false,\"metric\":\"mysql_global_status_connections\"}]}",
"chart_groups": [
{
"id": 0,
"dashboard_id": 0,
"name": "Default chart group",
"weight": 0,
"charts": [
{
"id": 56,
"group_id": 12,
"configs": "{\"name\":\"mysql-dom-ha\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"mysql_global_status_aborted_clients\"],\"layout\":{\"h\":2,\"w\":8,\"x\":0,\"y\":0,\"i\":\"0\"}}",
"weight": 0
},
{
"id": 57,
"group_id": 12,
"configs": "{\"name\":\"binlog日志缓存大小\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"mysql_global_status_binlog_cache_use\"],\"layout\":{\"h\":2,\"w\":8,\"x\":8,\"y\":0,\"i\":\"1\"}}",
"weight": 0
},
{
"id": 62,
"group_id": 12,
"configs": "{\"name\":\"5分钟平均查询数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_queries[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":16,\"y\":0,\"i\":\"2\"}}",
"weight": 0
},
{
"id": 63,
"group_id": 12,
"configs": "{\"name\":\"连接数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"mysql_global_status_threads_connected\"],\"layout\":{\"h\":2,\"w\":8,\"x\":0,\"y\":2,\"i\":\"3\"}}",
"weight": 0
},
{
"id": 64,
"group_id": 12,
"configs": "{\"name\":\"允许的最大连接数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"mysql_global_status_max_used_connections\"],\"layout\":{\"h\":2,\"w\":8,\"x\":8,\"y\":2,\"i\":\"4\"}}",
"weight": 0
},
{
"id": 65,
"group_id": 12,
"configs": "{\"name\":\"运行状态的连接数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"mysql_global_status_threads_running\"],\"layout\":{\"h\":2,\"w\":8,\"x\":16,\"y\":2,\"i\":\"5\"}}",
"weight": 0
},
{
"id": 66,
"group_id": 12,
"configs": "{\"name\":\"5分钟内平均慢查询数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_slow_queries[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":0,\"y\":4,\"i\":\"6\"}}",
"weight": 0
},
{
"id": 67,
"group_id": 12,
"configs": "{\"name\":\"5分钟内平均等待lock数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_table_locks_waited[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":8,\"y\":4,\"i\":\"7\"}}",
"weight": 0
},
{
"id": 68,
"group_id": 12,
"configs": "{\"name\":\"最近5分钟平均接受字节数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_table_locks_waited[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":16,\"y\":4,\"i\":\"8\"}}",
"weight": 0
},
{
"id": 69,
"group_id": 12,
"configs": "{\"name\":\"最近5分钟平均发送字节数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_bytes_sent[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":0,\"y\":6,\"i\":\"9\"}}",
"weight": 0
},
{
"id": 70,
"group_id": 12,
"configs": "{\"name\":\"最近5分钟平均打开的表数量\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_opened_tables[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":8,\"y\":6,\"i\":\"10\"}}",
"weight": 0
},
{
"id": 71,
"group_id": 12,
"configs": "{\"name\":\"最近5分钟平均缓存命中数\",\"mode\":\"prometheus\",\"link\":\"http://127.0.0.1:9090\",\"prome_ql\":[\"irate(mysql_global_status_table_open_cache_hits[5m])\"],\"layout\":{\"h\":2,\"w\":8,\"x\":16,\"y\":6,\"i\":\"11\"}}",
"weight": 0
}
]
}
]
}
]
4. FAQ
4.1 mysql有白名单或防火墙,容器内不能访问
###【思路】
用host模式启动------> (引出问题:启动多个服务端口会冲突)--------> 修改mysqld_exposrt启动端口
【解决】
修改docker-compose.yml文件如下:
version: '3.3'
services:
mysql_exporter_hq_m:
image: harbocto.boe.com.cn/bdteam/mysqld-exporter:latest
container_name: mysql_exporter_hq_m
network_mode: "host"
#ports:
# - 9104:9104
command: ["--web.listen-address=:9104"]
restart: always
environment:
DATA_SOURCE_NAME: "数据库用户:密码@(IP:端口)/"
mysql_exporter_hq_s:
image: harbocto.boe.com.cn/bdteam/mysqld-exporter:latest
container_name: mysql_exporter_hq_s
network_mode: "host"
#ports:
# - 9105:9104
command: ["--web.listen-address=:9105"]
restart: always
environment:
DATA_SOURCE_NAME: "数据库用户:密码@(IP:端口)/"
4.2 修改mysqld_exporter启动端口
命令
/bin/mysqld_exporter --web.listen-address=:9105
容器实现
完整示例见上文
command: ["--web.listen-address=:9105"]

边栏推荐
猜你喜欢

H.265网页播放器EasyPlayer获取视频流正常,但是播放出现黑屏是什么原因?

Zhong Hua, senior architect of Ali: China-Taiwan strategic thinking and architecture practice; including internal implementation manual

MySQL——增删改查进阶

MySQL【变量、流程控制与游标】

Confused!Ali was abused on the one hand, but was fortunate to be promoted to Huawei's technology, and successfully got the offer, with an annual salary of 40w

Bytes to beat three sides take offer: network + GC + + IO + redis + JVM red-black tree + data structure, to help you quickly into the giant!!!!!

MYSQL误删数据恢复

Install porterLB

online 方式创建索引触发trigger怎么办?

2022年最新的Android面试大厂必考174题(附带详细答案)
随机推荐
2022/08/02------Ugly number
With the help of Kubernetes kubekey speed installation
Intelligent security contract - delegatecall (2)
fatal error: jni.h: No such file or directory
PHP基础笔记-NO.2
二叉树求和路径问题解答与注记
【Azure 事件中心】使用Azure AD认证方式创建Event Hub Consume Client + 自定义Event Position
InnoDB 中不同SQL语句设置的锁
2022年7月国产数据库大事记
Protobuf Grpc使用异常 类型有未导出的方法,并且是在不同的软件包中定义
flink-sql 客户端 可以设置并行度 吗?断开算子链
ImportError: /lib/libgdal.so.26: undefined symbol: sqlite3_column_table_name
货比四家 version tb1.63
软件测试技术之如何编写测试用例(3)
金鱼哥RHCA回忆录:CL210管理计算资源--管理计算节点+章节实验
ImportError: /lib/libgdal.so.26: undefined symbol: sqlite3_column_table_name
实时渲染器不止lumion,Chaos Vantage你值得一试
[Notes] Introduction to machine learning
使用安全浏览器将网页保存为pdf的方法步骤
学弟:我适不适合转行做软件测试?