mysqld_exporter的安装
1、mysqld_exporter的安装
官网地址:https://prometheus.io/download
[root@localhost ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
2、解压mysqld_exporter
[root@localhost ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@localhost ~]# mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter
3、Mysql授权(因为Mysql在本机)
mysql> grant all on *.* to admin@'localhost' identified by '123456';
mysql> flush privileges;
4、创建mysql.cnf配置文件
[root@localhost ~]# cd /usr/local/mysqld_exporter
[root@localhost mysqld_exporter]# vim mysql.cnf
[client]
user=admin
password=123456
5、创建Mysqld_exporter启动脚本
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
Documentation=https://prometheus.io
Wants=network-online.target
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/mysql.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
6、启动mysqld_exporter
[root@localhost mysqld_exporter]# systemctl daemon-reload
[root@localhost mysqld_exporter]# systemctl start mysqld_exporter
7、浏览器访问本机IP:9104/metrics可以看到mysql的指标
8、修改prometheus配置文件,scrape_configs下面添加
[root@localhost mysqld_exporter]# vim /usr/local/prometheus/prometheus.yml
- job_name: 'mysql'
static_configs:
- targets: ['localhost:9104']
9、重启Prometheus服务
[root@localhost mysqld_exporter]# systemctl restart prometheus
10、在Prometheus界面可以看到mysql相关指标
11、查看Targets
二、Grafana配置
1、Granfana 导入Mysql 监控图表
推荐图标ID:https://grafana.com/dashboards/7362
2、输入图标ID
3、输入导入图标ID等待3秒弹出如下,修改后导入即可
4、监控展示
至此,Prometheus监控Mysql完毕。
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
评论