Prometheus监控之Mysql篇

小柒博客
小柒博客
小柒博客
313
文章
92
评论
2020-04-1015:59:07 评论 4.4K 1596字阅读5分19秒

mysqld_exporter的安装

1、mysqld_exporter的安装

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

Prometheus监控之Mysql篇

[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篇

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篇

11、查看Targets

Prometheus监控之Mysql篇

二、Grafana配置

1、Granfana 导入Mysql 监控图表

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

Prometheus监控之Mysql篇

2、输入图标ID

Prometheus监控之Mysql篇

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

Prometheus监控之Mysql篇

4、监控展示

Prometheus监控之Mysql篇

Prometheus监控之Mysql篇

Prometheus监控之Mysql篇

至此,Prometheus监控Mysql完毕。

继续阅读
  • 微信号
  • 微信扫一扫加我!
  • weinxin
  • 微信公众号
  • 微信扫一扫关注我!
  • weinxin
小柒博客
  • 本文由 发表于 2020-04-1015:59:07
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: