Prometheus + Granfana + mysqld_exporter 监控MySQL数据库
参照:
https://www.cnblogs.com/xiangsikai/p/11289675.html
iptables -I INPUT 11 -p tcp --dport 9104 -j ACCEPT
/etc/init.d/iptables save
groupadd prometheus
useradd -g prometheus -m -d /opt/prometheus/ -s /sbin/nologin prometheus
tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local
mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
cd /usr/local/mysqld_exporter/
touch .my.cnf
cat >>.my.cnf<
[client]
user=exporter
password=xxxxxyyyyy
EOF
chown -R prometheus:prometheus mysqld_exporter
mysql -u root -p
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'exporter'@'172.xx.xx.xx' IDENTIFIED BY 'xxxxxxyyyy';
flush privileges;
./mysqld_exporter --config.my-cnf=.my.cnf &
lsof -i:9104
cd /usr/lib/systemd/system
touch mysqld_exporter.service
cat >> mysqld_exporter.service<
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl restart mysqld_exporter.service
#如果启动失败,可以直接到文件目录下后台运行mysqld_exporter
cd /usr/local/mysqld_exporter/
chown -R prometheus:prometheus mysqld_exporter
./mysqld_exporter --config.my-cnf=.my.cnf &
lsof -i:9104
#服务端Prometheus 添加对mysqld_exporter端的监控
vi /usr/local/prometheus/prometheus.yml
- job_name: 'xxx_db'
static_configs:
- targets: ['172.xx.xx.xx:9104']
labels:
instance: xxxx_db_yyy
./promtool check config prometheus.yml
systemctl restart prometheus
systemctl restart grafana-server
+ ==》 import==》Grafana.com Dashboard:输入 7362 ==》prometheus:Prometheus==》Import
Granfana 导入Mysql 监控图表
推荐图标ID:https://grafana.com/dashboards/7362