prometheus监控mysql8.x以及主从监控告警

mysql8.x主从部署请看下面文档 docker和yum安装的都有

Docker部署mysql8.x版本互为主从_争取不加班!的博客-CSDN博客

Mysql8.x版本主从加读写分离(一) mysql8.x主从_myswl8双主一从读写分离_争取不加班!的博客-CSDN博客

安装部署mysqld_exporter

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

tar -xvzf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local/

cd /usr/local/mysqld_exporter-0.13.0.linux-amd64/

vim ./my.cnf 编辑一个文件 启动exporter的用户和密码

client

host=localhost 监控其他主机换成ip即可

user=root 注意用户权限 创建一个有权限的用户

port=3306

password=Zxcvbnm@2022

nohup ./mysqld_exporter --config.my-cnf=./my.cnf --web.listen-address=":9104" 指定端口

& 运行

--web.listen-address=":9104" 运行多个的话指定其他端口即可

ps -ef |grep mysqld_exporter

kill -9 114835 关闭

然后编辑prometheus配置配件

vim prometheus.yml

systemctl restart prometheus 重启

启动mysql_exporter

vim nohup 看一下启动日志

192.168.11.193:9104/metrics 启动后查看 有数据则启动成功

以上配置好以后在Grafana中配置mysql的监控模板

在Grafana官网中下载mysql的监控模板 Dashboards | Grafana Labs

下载好以后来到GrafanaWEB页面

配置完成!!!

Grafana mysql8.x监控模板id 14057

然后编写mysql的告警规则

#mysql服务挂掉时触发告警

  • alert: Mysql状态

expr: mysql_up == 0

for: 10s

labels:

severity: warning

annotations:

summary: ' {{ $labels.instance }} Mysql服务 '

description: " {{ $labels.instance }} Mysql服务不可用 请检查"

#mysql主从IO线程停止时触发告警

  • alert: Mysql主从IO线程检测

expr: mysql_slave_status_slave_io_running == 0

for: 5s

labels:

severity: error

annotations:

summary: " {{ $labels.instance }} Mysql从节点IO线程"

description: "Mysql主从IO线程故障,请检测"

#mysql主从sql线程停止时触发告警

  • alert: Mysql主从sql线程检测

expr: mysql_slave_status_slave_sql_running == 0

for: 5s

labels:

severity: error

annotations:

summary: "{{ $labels.instance }} Mysql从节点sql线程"

description: "Mysql主从sql线程故障,请检测"

systemctl restart alertmanager prometheus 重启 alertmanager和 prometheus

stop slave sql_thread; 停掉 从库的sql线程看下

收到告警配置完成

相关推荐
成为你的宁宁20 小时前
【Prometheus Operator 监控 K8S集群的Calico 与 Ingress-Nginx 组件】
kubernetes·prometheus
Adorable老犀牛21 小时前
Prometheus 常用告警规则 rules.yml
开发语言·prometheus·exporter·nodeexpoeter
Jinkxs1 天前
Prometheus - 监控微服务:Spring Boot 应用指标暴露与监控
spring boot·微服务·prometheus
云烟成雨TD1 天前
Spring AI 1.x 系列【50】可观测性:接入 Prometheus + Grafana
人工智能·spring·prometheus
YDS8292 天前
DeepSeek RAG&MCP + Agent智能体项目 —— 集成ELK日志管理系统和Prometheus监控系统
java·elk·ai·springboot·agent·prometheus·deepseek
暮云星影2 天前
个人总结 搭建Docker监控
docker·容器·grafana·prometheus
成为你的宁宁5 天前
【基于 Prometheus Operator 监控 K8s控制器、调度器、代理组件】
kubernetes·prometheus
溜达的大象5 天前
服务器挂了等用户报障?我用Prometheus搭了一套监控告警,服务器出状况第一时间通知我
服务器·php·prometheus
tudoSearcher5 天前
日志、指标、链路追踪:可观测性三支柱深度解析
运维·服务器·网络·prometheus
IT策士6 天前
第 41 篇 k8s之监控:Metrics Server 与 Prometheus 快速上手
容器·kubernetes·prometheus