Copy mkdir /data
cd /usr/local/src
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gz
mv mysqld_exporter-0.15.0.linux-amd64 /data/mysqld_exporter
cd /data/mysqld_exporter
cat >> mysql_node.cnf << EOF
[client]
host="1.1.1.1"
port=3306
user=exporter
password=123456
EOF
Copy GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'%' identified by '123456';
GRANT SELECT ON performance_schema.* TO 'exporter'@'%';
flush privileges;
Copy ./mysqld_exporter --config.my-cnf=="./mysql_node.cnf" &
ss -tln |grep 9104
Copy cat >> /usr/lib/systemd/system/mysqld_exporter.service << EOF
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
Type=simple
ExecStart=/data/mysqld_exporter/mysqld_exporter --config.my-cnf=/data/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
Copy systemctl daemon-reload
systemctl enable mysqld_exporter
systemctl start mysqld_exporter
systemctl status mysqld_exporter
$ ss -antpl |grep 9104
LISTEN 0 128 [::]:9104 [::]:* users:(("mysqld_exporter",pid=3141,fd=3))
Copy curl -s localhost:9104/metrics |grep ^mysql_up
mysql_up 1 ----> 1 说明收集监控信息成功, 0 代表不成功
Copy root@monitor-1:/data/monitor/prometheus cat prometheus.yml
#- job_name: 'mysql'
# static_configs:
# - targets: ['x.x.x.x:9104']
# labels:
# instance: db1
... 略
# MySQL数据库相关
- job_name: 'MySQL数据库'
static_configs:
file_sd_configs:
- refresh_interval: 30s
files:
- "vhosts/mysql/*.json"
Copy root@monitor-1:/data/monitor/prometheus# cat vhosts/mysql/saas.json
[
{
"targets": ["2.2.2.2:9104"],
"labels": {
"label": "xxxx使用",
"account": "account@xxx.com",
"cloud": "xxxxx",
"instance": "1.1.1.1:3306" # mysql不在服务器,覆盖 instance
}
}
]
Copy ./promtool check config prometheus.yml
curl -XPOST localhost:8090/-/reload # 主配置文件热加载,修改子配置会自动加载