prometheus应用之监控mysql

1 下载安装

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter /usr/local/bin/mysqld_exporter

2 添加监控mysql用户

 CREATE USER 'exporter'@'localhost' IDENTIFIED BY '123456';
 GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';

3 配置启动服务

vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
Documentation=https://github.com/prometheus/mysqld_exporter
After=network.target

[Service]
Type=simple
User=mysql
Environment=DATA_SOURCE_NAME=exporter:123456@(localhost:3306)/
ExecStart=/usr/local/bin/mysqld_exporter --web.listen-address=0.0.0.0:9104 \
  --log.level=error \
  --collect.info_schema.innodb_metrics \
  --collect.info_schema.innodb_tablespaces \
  --collect.info_schema.innodb_cmp \
  --collect.info_schema.innodb_cmpmem
Restart=on-failure
[Install]
WantedBy=multi-user.target

4 启动mysql-exporter

systemctl daemon-reload 
systemctl start mysqld_exporter
systemctl enable mysqld_exporter

5 测试metrics

curl localhost:9104/metrics

6 配置prometheus


- job_name: 'mysql' static_configs: - targets: ['192.168.160.22:9104'] 检查语法 [root@prometheus-server prometheus]# ./promtool check config prometheus.yml Checking prometheus.yml SUCCESS: 0 rule files found 热更新 [root@prometheus-server prometheus]# ps -ef|grep prometheus root 870 1 0 11:07 ? 00:00:03 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/ root 1530 1434 0 12:03 pts/0 00:00:00 grep --color=auto prometheus [root@prometheus-server prometheus]# kill -hup 870
prometheus应用之监控mysql

7 grafana导入图表展示

模板id 7362
prometheus应用之监控mysql

参考:https://github.com/prometheus/mysqld_exporter

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
avatar

发表评论

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