4. MySQL添加到prometheus监控
1. 上传mysqld-explorer到要被监控的主机解压缩¶
# 10.0.8.5
tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
root@4c16g:/home/ubuntu# tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
mysqld_exporter-0.13.0.linux-amd64/
mysqld_exporter-0.13.0.linux-amd64/LICENSE
mysqld_exporter-0.13.0.linux-amd64/NOTICE
mysqld_exporter-0.13.0.linux-amd64/mysqld_exporter
root@4c16g:/home/ubuntu# cd mysqld_exporter-0.13.0.linux-amd64/
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# ls
LICENSE mysqld_exporter NOTICE
2. 登录数据库,创建用户¶
mysql -uroot -p123456
# 创建一个可以访问数据库的用户
grant select,replication client,process on *.* to 'mysql_monitor'@'localhost' identified by '12345678';
flush privileges;
3. 创建数据库用户名密码文件¶
vim .my.cnf
[client]
user=mysql_monitor
password=12345678
4. 启动服务¶
nohup ./mysqld_exporter --config.my-cnf=/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64/.my.cnf &
jobs
netstat -tunlp|grep 9104
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# vim .my.cnf
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64#
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# ls
LICENSE mysqld_exporter NOTICE
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# ls -a
. .. LICENSE .my.cnf mysqld_exporter NOTICE
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64#
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# nohup ./mysqld_exporter --config.my-cnf=/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64/.my.cnf &
[2] 753626
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# nohup: ignoring input and appending output to 'nohup.out'
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# jobs
[1]- Running nohup ./prometheus & (wd: /home/ubuntu/prometheus-2.33.3.linux-amd64)
[2]+ Running nohup ./mysqld_exporter --config.my-cnf=/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64/.my.cnf &
root@4c16g:/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64# netstat -tunlp|grep 9104
tcp6 0 0 :::9104 :::* LISTEN 753626/./mysqld_exp
5. 浏览器访问查看¶
10.0.8.5:9104
点开metrics查看所有监控项

6. 添加到prometheus监控¶
# 10.0.8.5
vim prometheus.yml
# 新加10.0.8.5数据库监控
- job_name: "MySQL"
static_configs:
- targets: ["10.0.8.5:9104"]
7. 重启¶
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64# ps -ef|grep prometheus
root 723051 711590 0 13:44 pts/0 00:00:01 ./prometheus
root 766771 711590 0 14:04 pts/0 00:00:00 grep --color=auto prometheus
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64#
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64# netstat -tunlp|grep 9090
tcp6 0 0 :::9090 :::* LISTEN 723051/./prometheus
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64#
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64#
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64# kill -9 723051
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64#
[1]- Killed nohup ./prometheus
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64#
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64# nohup ./prometheus &
[3] 768489
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64# nohup: ignoring input and appending output to 'nohup.out'
root@4c16g:/home/ubuntu/prometheus-2.33.3.linux-amd64# jobs
[2]- Running nohup ./mysqld_exporter --config.my-cnf=/home/ubuntu/mysqld_exporter-0.13.0.linux-amd64/.my.cnf & (wd: /home/ubuntu/mysqld_exporter-0.13.0.linux-amd64)
[3]+ Running nohup ./prometheus &
8. 查看target¶
10.0.8.5:9090

最后更新:
2022-02-25 03:53:42