美文网首页个人学习监控
Prometheus监控Mysql服务器

Prometheus监控Mysql服务器

作者: 阿当运维 | 来源:发表于2021-05-19 14:26 被阅读0次

mysql_exporter:用于收集MySQL性能信息。监听端口:9104
项目地址:https://github.com/prometheus/mysqld_exporter

采集器位置: /usr/local/jiankong/mysqld_exporter

安装采集器

cd /usr/local/jiankong/mysqld_exporter
tar zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter

在mysql中创建一个账户账户用于搜集数据

grant process,replication client,select on *.* to 'exporter'@'%' identified by 'ex123456';
grant process,replication client,select on *.* to 'exporter'@'localhost' identified by 'ex123456';
flush privileges;

插件目录下创建my.cnf
vim /usr/local/jiankong/mysqld_exporter/my.cnf

[client]
user=exporter
password=ex123456

加入系统服务

vim /usr/lib/systemd/system/mysqld_exporter.service

[Unit]
Description=mysqld_exporter
[Service]
ExecStart=/usr/local/jiankong/mysqld_exporter/mysqld_exporter  --config.my-cnf=/usr/local/jiankong/mysqld_exporter/my.cnf
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

重载服务,启动服务
systemctl daemon-reload
systemctl start mysqld_exporter


image.png

Prometheus加入监控端

访问一下接口http://192.168.1.112:9104/metrics

image.png
没问题。开始配置promethues
vim promethues.yml 加入被监控主机采集接口
- job_name: 'mysql'
    metrics_path: '/metrics'
    static_configs:
    - targets: ['192.168.1.112:9104']

重启服务或者kill -HUP PID

image.png

Grafana添加仪表盘

MYSQL仪表盘推荐ID:7362


image.png

相关文章

网友评论

    本文标题:Prometheus监控Mysql服务器

    本文链接:https://www.haomeiwen.com/subject/xocpjltx.html