新版prometheus+grafana监控mysql

prometheus:v2.36.2
grafana:9.0.7

1、安装mysql_exporter

[root@mysqld ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz [root@mysqld ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/ [root@mysqld ~]# ln -sv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /usr/local/prometheus_mysqld

2、在MySQL中创建用户并授权

mysql> CREATE USER 'mysqld_exporter'@'%' IDENTIFIED BY 'mysqld_exporter';
mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysqld_exporter'@'%' identified by 'mysqld_exporter'; 
mysql> GRANT SELECT ON *.* TO 'mysqld_exporter'@'%';

新版prometheus+grafana监控mysql_第1张图片

3、编写mysqld_exporter的配置文件

vim /usr/local/prometheus_mysqld/.my.cnf 
[client]
user=mysqld_exporter
password=mysqld_exporter
port=3306

新版prometheus+grafana监控mysql_第2张图片

4、配置systemd启动mysqld_exporter

vim /lib/systemd/system/mysqld_exporter.service
[Unit]
Description=Mysqld_exporter
After=network.target
[Service]
ExecStart=/usr/local/prometheus_mysqld/mysqld_exporter --config.my-cnf=/usr/local/prometheus_mysqld/.my.cnf
[Install]
WantedBy=multi-user.target

systemctl启动

systemctl daemon-reload
systemctl start mysqld_exporter
systemctl enable mysqld_exporter

5、在Prometheus-configmap端添加监控端

    - job_name: 'mysql_db'
      static_configs:
      - targets:
        - 192.168.20.230:9104

新版prometheus+grafana监控mysql_第3张图片

重载prometheus

curl -XPOST http://192.168.20.20:32471/-/reload

访问prometheus的targets

新版prometheus+grafana监控mysql_第4张图片

6、grafana导入模板

新版prometheus+grafana监控mysql_第5张图片

新版prometheus+grafana监控mysql_第6张图片

新版prometheus+grafana监控mysql_第7张图片

你可能感兴趣的:(Prometheus,云计算,prometheus,数据库)