51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Prometheus监控Mysql

mysqld_exporter的安装

1、mysqld_exporter的安装

官网地址:https://prometheus.io/download

Prometheus监控Mysql-图片1

[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的指标

Prometheus监控Mysql-图片2

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相关指标

Prometheus监控Mysql-图片3

11、查看Targets

Prometheus监控Mysql-图片4

二、Grafana配置

1、Granfana 导入Mysql 监控图表

推荐图标ID:https://grafana.com/dashboards/7362

Prometheus监控Mysql-图片5

2、输入图标ID

Prometheus监控Mysql-图片6

3、输入导入图标ID等待3秒弹出如下,修改后导入即可

Prometheus监控Mysql-图片7

4、监控展示

Prometheus监控Mysql-图片8

Prometheus监控Mysql-图片9

Prometheus监控Mysql-图片10

至此,Prometheus监控Mysql完毕。
继续阅读 Prometheus最后更新:2024-1-24

赞(0)
未经允许不得转载:工具盒子 » Prometheus监控Mysql