监控之Prometheus+grafana+mysqld_exporter
mysqld_exporter监控MySQL
一、服务器环境:
二、创建数据库账户
创建数据库账户获取MySQL参数变量指标
root@tidb04 00:48: [(none)]> GRANT SELECT, PROCESS, rEPLICATION CLIENT ON *.* TO 'exporter'@'127.0.0.1' identified by 'EDy&exporter1202' WITH MAX_USER_CONNECTIONS 3;flush privileges;
Query OK, 0 rows affected, 1 warning (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
[root@tidb04 prometheus]# cat /opt/server/exporter/mysqld_exporter/.my.cnf
[client]
host=127.0.0.1
user=exporter
password=EDy&exporter1202
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
三、mysqld_exporter启动脚本
[root@tidb04 exporter]# cat /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=prometheus
WorkingDirectory=/opt/server/exporter
ExecStart=/opt/server/exporter/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/server/exporter/mysqld_exporter/.my.cnf --web.listen-address=:19102 \
--collect.engine_innodb_status \
--collect.info_schema.tablestats \
--collect.info_schema.query_response_time \
--collect.info_schema.tables.databases="*" \
--collect.info_schema.innodb_tablespaces
Restart=on-failure
RestartSec=10s
SuccessExitStatus=0
# May not be honored if higher than kernel limit (sysctl fs.file-max) or process
# limit (sysctl fs.nr_open). Also may not be honored if lower than systemd limit
# (system.conf) or systemd user limit (user.conf).
LimitNOFILE=300000
[Install]
WantedBy=multi-user.target
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
服务启动命令:
同上tidb05服务器也重复执行如上命令
四、prometheus配置
在配置文件/data/soft/prometheus/prometheus.yml 最后添加如下参数:
重服务:systemctl restart prometheus
验证mysqld_exporter是否接入到prometheus:
添加的mysqld_exporter的服务器都可以查到
五、导入mysqld_exporter dashboard模版
监控MySQL服务 导入mysqld_exporter dashboard模版
登录 grafana官网查找node_exporter dashboard的模板 导入到自建的grafana系统:
dashboard的模板查找地址: h ttps://grafana.com/grafana/dashboards
找到官房提供的MySQL_exporter的dashboard的模板id: 14057 导入到grafana控制台
https://grafana.com/oss/prometheus/exporters/mysql-exporter/?tab=dashboards
下面是具体的导入过程:
完成对数据库的监控: