Prometheus监控MySQL
一、采集MySQL数据
Mysqld_exporter下载地址:https://github.com/prometheus/mysqld_exporter
1.1 安装
# 解压
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /usr/local/mysqld_exporter-0.12.1
# 创建软链接
ln -s /usr/local/mysqld_exporter-0.12.1/ /usr/local/mysqld_exporter
1.2 添加系统服务
[Unit]
Description=mysql Monitoring System
Documentation=mysql Monitoring System
[Service]
ExecStart=/usr/local/mysqld_exporter/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.binlog_size \
--collect.info_schema.clientstats \
--collect.perf_schema.eventswaits \
--config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
[Install]
WantedBy=multi-user.target
添加配置服务
vi /usr/local/mysqld_exporter/.my.cnf
[client]
host=192.168.64.104
user=exporter
password=123456
1.3 MySQL添加授权账户
# 授权
MariaDB [(none)]> GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'exporter'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.002 sec)
# 刷新权限
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.005 sec)
1.4 启动mysqld_exporter
systemctl start mysqld_exporter
1.5 查看metrics
1.6 加入prometheus监控
修改prometheus配置文件 prmetheus.yml
- job_name: 'mysql_monitor'
static_configs:
- targets: ['192.168.64.101:9104']
重启prometheus服务
systemctl restart prometheus
1.7 Grafana接入监控模板
导入MySQL状态监控模板 14057
类似的 监控redis/Nginx/ES/jvm同理。参考对应xxx_exporter博客即可
参考博客
标签:
Prometheus
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?