Prometheus监控Rds


  • 下载客户端:

https://prometheus.io/download/#mysqld_exporter

https://github.com/prometheus/mysqld_exporter/releases

  • 下载最新版本
    https://blog.csdn.net/allway2/article/details/106986309/
https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /opt/prometheus_exporter/

mv mysqld_exporter-0.13.0.linux-amd64  mysqld_exporter
[root@prometheus mysqld_exporter]# pwd
/opt/prometheus_exporter/mysqld_exporter
[root@prometheus mysqld_exporter]# ll
total 14624
-rw-r--r-- 1 3434 3434    11357 May 31 15:36 LICENSE
-rwxr-xr-x 1 3434 3434 14955898 May 31 15:30 mysqld_exporter
-rw-r--r-- 1 3434 3434       65 May 31 15:36 NOTICE
  • 创建配置文件目录
mkdir -p /opt/prometheus_exporter/mysqld_exporter/conf

chown -R prometheus:prometheus /opt/prometheus_exporter/
  • 编辑配置文件
vim conf/rds.conf

[client]
user=XXXX
password=XXXX
port=XXXX
host=rm-xxxxxxxxxXXx.mysql.rds.aliyuncs.com

注意:这里推荐使用高权限账号。

  • 启动进程:
cd /opt/prometheus_exporter/mysqld_exporter

nohup ./mysqld_exporter --config.my-cnf="conf/rds.conf" --web.listen-address=":9104" &


[root@prometheus mysqld_exporter]# netstat -pnltu | grep 9104
tcp6       0      0 :::9104                 :::*                    LISTEN      6210/./mysqld_expor 

观察是否有报错信息,如果没有报错信息,就可以封装service服务了

  • 访问metrics
curl http://localhost:9104/metrics
#curl http://localhost:9105/metrics

如果数据输出正常,则表示成功。

三、promethus增加job

vim prometheus.yml 
  - job_name: 'mysqld_exporter'
    static_configs:
    - targets: ['localhost:9104']

最后,重启prometheus

systemctl restart prometheus

journalctl -u prometheus -fn 200

确保mysqd_exporter状态为UP

  • Grafana导入Dashboards
    下载json文件
    https://files.cnblogs.com/files/xiao987334176/MySQL监控-rds.zip

解压之后,里面就是一个json文件

点击import

每个图表,都有解释。

其中要特别注意,连接使用率,高于80%,就表示RDS有异常了。