prometheus监控mysql
创建一个用于mysqld_exporter连接到MySQL的用户并赋予所需的权限
mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'mysqld_exporter'@'localhost' identified by '000000'; mysql> GRANT SELECT ON performance_schema.* TO 'mysqld_exporter'@'localhost'; mysql> flush privileges;
创建一个用于连接MySQL的配置文件
mysqld_exporter默认会读取~/.my.cnf
文件。这里是创建在mysqld_exporter的安装目录下的。
$ vim /usr/local/prom/mysqld_exporter_0110/.my.cnf [client] user=mysqld_exporter password=000000
创建Systemd服务
#vim /etc/systemd/system/mysql_exporter.service
[Unit]
Description=mysql_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prom/exporter/mysqld_exporter_0110/mysqld_exporter --config.my-cnf=/usr/local/prom/exporter/mysqld_exporter_0110/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动mysqld_exporter
# systemctl start mysql_exporter
# systemctl status mysql_exporter
添加prometheus相关配置
# vi prometheus280/prometheus.yml - job_name: 'mysql' static_configs: - targets: ['localhost:9104'] labels: instance: db1
重启prometheus即可