1 ) 下载 mysqld_exporter :
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar -zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
chown -R work.work mysqld_exporter/
2 ) 登录mysql为exporter创建账号并授权:
# 2.1 ) 创建数据库用户:
mysql> CREATE USER 'exporter'@'%' IDENTIFIED BY '123456';
# 2.2 ) 可查看主从运行情况查看线程,及所有数据库:
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
# 2.3 ) 创建mysql配置文件、运行时可免密码连接数据库:
vim /data/soft/mysqld_exporter/.mysqld_exporter.cnf
[client]
host= MYsql的IP地址
port=3306
user=exporter
password=123456
3 ) 启动exporter客户端
vim /data/soft/mysqld_exporter/my_exporter.sh
#!/bin/bash
cd /data/soft/mysqld_exporter
./mysqld_exporter --config.my-cnf /data/soft/mysqld_exporter/.mysqld_exporter.cnf \
--collect.auto_increment.columns \
--collect.binlog_size \
--collect.engine_innodb_status \
#--collect.engine_tokudb_status \
--collect.global_status \
--collect.info_schema.tables \
--collect.info_schema.innodb_tablespaces \
--collect.info_schema.innodb_metrics \
--collect.global_status \
--collect.global_variables \
--collect.slave_status \
--collect.info_schema.processlist \
--collect.perf_schema.tablelocks \
--collect.perf_schema.eventsstatements \
--collect.perf_schema.eventsstatementssum \
--collect.perf_schema.eventswaits \
--collect.auto_increment.columns \
--collect.perf_schema.tableiowaits \
--collect.perf_schema.indexiowaits \
--collect.info_schema.userstats \
--collect.info_schema.clientstats \
--collect.info_schema.tablestats \
--collect.info_schema.schemastats \
--collect.perf_schema.file_events \
--collect.perf_schema.file_instances \
--collect.perf_schema.replication_group_member_stats \
--collect.perf_schema.replication_applier_status_by_worker \
--collect.slave_hosts \
--collect.info_schema.innodb_cmp \
--collect.info_schema.innodb_cmpmem \
--web.listen-address=0.0.0.0:9104
4 ) 启动脚本:
# 4.1 ) 脚本内容:
vim /usr/lib/systemd/system/mysql_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/data/soft/mysqld_exporter/mysqld_exporter \
--config.my-cnf /data/soft/mysqld_exporter/.mysqld_exporter.cnf \
--collect.auto_increment.columns \
--collect.binlog_size \
--collect.engine_innodb_status \
#--collect.engine_tokudb_status \
--collect.global_status \
--collect.info_schema.tables \
--collect.info_schema.innodb_tablespaces \
--collect.info_schema.innodb_metrics \
--collect.global_status \
--collect.global_variables \
--collect.slave_status \
--collect.info_schema.processlist \
--collect.perf_schema.tablelocks \
--collect.perf_schema.eventsstatements \
--collect.perf_schema.eventsstatementssum \
--collect.perf_schema.eventswaits \
--collect.auto_increment.columns \
--collect.perf_schema.tableiowaits \
--collect.perf_schema.indexiowaits \
--collect.info_schema.userstats \
--collect.info_schema.clientstats \
--collect.info_schema.tablestats \
--collect.info_schema.schemastats \
--collect.perf_schema.file_events \
--collect.perf_schema.file_instances \
--collect.perf_schema.replication_group_member_stats \
--collect.perf_schema.replication_applier_status_by_worker \
--collect.slave_hosts \
--collect.info_schema.innodb_cmp \
--collect.info_schema.innodb_cmpmem \
--web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
# 4.2 ) 启动信息:
systemctl daemon-reload
systemctl enable mysql_exporter
systemctl start mysql_exporter
systemctl status mysql_exporter
5 ) 配置Prometheus:
vim prometheus.yml
......
- job_name: 'mysql_exporter'
static_configs:
- targets: ['IP地址:9104']
labels:
operator: 'Ucloud'
area: '北京二D'
env: 'Pord'
6 ) Grafana 添加模板:
6.1 ) 添加模板:
7362 or 6239
6.2 )