【prometheus】监控MySQL并实现可视化

目录

一、概述

1.1下载解压mysqld_exporter

1.2创建MySQL授权用户

1.3配置my.cnf

1.4启动mysqld_exporter

1.5prometheus配置修改

二、Grafana展示


【Prometheus】概念和工作原理介绍_prometheus工作原理

【Prometheus】k8s集群部署node-exporter

【prometheus】k8s集群部署prometheus server-CSDN博客

【prometheus】k8s集群部署Grafana安装和配置

【prometheus】k8s集群部署AlertManager实现邮件和钉钉告警-CSDN博客


一、概述


mysqld_exporter 是一个用于监控 MySQL 服务器的开源工具,它是由 Prometheus 社区维护的一个官方 Exporter。该工具通过连接到 MySQL 服务器并执行各种查询来收集关于 MySQL 服务器性能和状态的指标,并将这些指标暴露给 Prometheus 监控系统。

以下是 mysqld_exporter 的一些主要特点和功能:

  • 指标收集: mysqld_exporter 通过执行 SQL 查询来收集关于 MySQL 服务器的各种指标,包括查询性能、连接状态、InnoDB 状态、复制状态等。
  • Prometheus 兼容: mysqld_exporter 输出的指标符合 Prometheus 的指标格式,并且可以直接由 Prometheus 进行收集和存储。
  • 灵活的配置: 用户可以通过配置文件或命令行参数来配置 mysqld_exporter 的行为,包括指定要监控的 MySQL 实例、连接参数、指标的收集频率等。
  • 安全性: mysqld_exporter 支持通过 TLS/SSL 进行安全连接,以确保监控数据的机密性和完整性。
  • 多版本支持: mysqld_exporter 可以与多个 MySQL 版本兼容,并且可以通过配置选择性地启用或禁用特定版本的指标收集。
  • 自定义查询: 用户可以通过配置文件自定义要执行的 SQL 查询,以收集特定于其环境的自定义指标。
  • 易于部署: mysqld_exporter 可以作为一个独立的二进制文件部署,并且支持多种部署方式,包括 Docker 容器、系统服务等。

总的来说,mysqld_exporter 是一个功能强大且易于使用的工具,可以帮助用户监控和诊断其 MySQL 服务器的性能和健康状态,从而及时发现和解决潜在的问题。

官网: Download | Prometheus

MySQLExpoter: GitHub - prometheus/mysqld_exporter: Exporter for MySQL server metrics

【Linux】Centos7 shell实现MySQL5.7 tar 一键安装_shell一键安装mysql5.7.44-CSDN博客


1.1下载解压mysqld_exporter


复制代码
wget --no-check-certificate   https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz


cd mysqld_exporter-0.15.1.linux-amd64
cp -ar mysqld_exporter /usr/local/bin/
chmod +x /usr/local/bin/mysqld_exporter

1.2创建MySQL授权用户


复制代码
# 创建数据库用户。
CREATE USER 'mysql_exporter'@'192.168.2.139' IDENTIFIED BY 'Abcdef123!.';

# 对mysql_exporter用户授权
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'192.168.2.139';

1.3配置my.cnf


创建mysql配置文件、运行时可免密码连接数据库

复制代码
cd mysqld_exporter-0.15.1.linux-amd64

cat > my.cnf << EOF
[client]
host=192.168.2.211
port=3306
user=mysql_exporter
password=Abcdef123!.

[client.servers]
host=192.168.2.211
port=3306
user=mysql_exporter
password=Abcdef123!.

EOF

1.4启动mysqld_exporter


直接命令行启动mysql_exporter客户端

复制代码
nohup ./mysqld_exporter --config.my-cnf=./my.cnf &

也可以注册为服务

复制代码
cat <<EOF>>  /usr/lib/systemd/system/mysqld-exporter.service 
[Unit]
Description=mysqld_exporter


[Service]
User=root
ExecStart=/root/prome/mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter --config.my-cnf /root/prome/mysqld_exporter-0.15.1.linux-amd64/my.cnf --web.listen-address=0.0.0.0:9104 

--collect.slave_status

--collect.binlog_size

--collect.info_schema.processlist

--collect.info_schema.innodb_metrics

--collect.engine_innodb_status

--collect.perf_schema.file_events

--collect.perf_schema.replication_group_member_stats

Restart=on-failure

复制代码
[Install]
WantedBy=multi-user.targe
EOF

1.5prometheus配置修改


修改prometheus-cfg.yaml文件,添加如下

复制代码
  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.124.16:9104']

kubectl apply  -f prometheus-alertmanager-cfg.yaml
kubectl delete -f prometheus-deploy.yaml
kubectl apply  -f prometheus-deploy.yaml


curl -XPOST localhost:9090/-/reload

登录 promethetus 可以看到采集到了


二、Grafana展示


官网模板地址Dashboards | Grafana Labs

mysql-overview_rev5.json

导入模板

选择"Import Json File"

导入模板后,选择import

展示成功

参考链接:

mysqld_exporter部署-CSDN博客

相关推荐
阳光九叶草LXGZXJ6 小时前
达梦数据库-报错-15-列【XXX】长度超出定义
linux·运维·数据库·sql·学习
字节渡客6 小时前
Redis键明明过期了,业务还在读到旧数据
数据库·redis·spring
OnlineProxy9 小时前
亚马逊多账号运营:如何在规避“关联封号”风险的同时实现电商规模化扩张
服务器·数据库·redis
辻弋20110 小时前
五年前的旅行视频糊成马赛克?Video2X用Real-ESRGAN逐帧重建细节,但只支持Windows、集显用户建议直接放弃
服务器·数据库·windows·游戏引擎·电脑
可乐鸡翅yeah_11 小时前
业务中 M3U8 水印相关坑,硬水印和动态水印区别
前端·网络·数据库·ffmpeg·m3u8在线
石头麻辣鱼11 小时前
Bamboo 调度系统 OceanBase 适配实战:存储过程迁移踩过的三个大坑
数据库
龙亘川12 小时前
数智驱动民政升级 精准守护民生保障
大数据·数据库·人工智能
念何架构之路12 小时前
zap扩展生态与总结
java·前端·数据库
晚安日记wanna12 小时前
MySQL 回表为什么这么慢?5 种优化手段逐个拆解
数据库·mysql·性能优化
第七页独白12 小时前
汽车零件厂如何通过 QMS 真正落地 IATF 16949——QMS软件系统:品质检验-内审稽核-8d客诉管理:全星质量管理软件系统
java·前端·数据库