prometheus监控rabbitmq有两种方式。
第一种,RabbitMQ内部集成Prometheus来获取指标
3.8.0之前版本,RabbitMQ可以使用单独的插件prometheus_rabbitmq_exporter来向Prometheus公开指标,要单独下载到RabbitMQ安装目录中进行安装;
prometheus_rabbitmq_exporter:https://github.com/deadtrickster/prometheus_rabbitmq_exporter
3.8.0版开始,RabbitMQ附带了内置的Prometheus&Grafana支持。虽然内置了该插件,但也要进行安装
rabbitmq-prometheus:https://github.com/rabbitmq/rabbitmq-prometheus
第二种:使用独立程序来获取指标(RabbitMQ_exporter)
不管什么版本都能使用,要单独启动exporter进程
rabbitmq_exporter:https://github.com/kbudde/rabbitmq_exporter
RabbitMQ 官方监控介绍:
https://www.rabbitmq.com/monitoring.html
https://www.rabbitmq.com/prometheus.html#overview-prometheus
一、第一种方式
1、RabbitMq启动prometheus监控插件
1)参考官网文档: https://www.rabbitmq.com/prometheus.html
2)rabbitmq内置的有prometheu插件,需要开启
# 可以在线开启,注意必须要rabbitmq服务存货
rabbitmq-plugins enable rabbitmq_prometheus
# 关闭插件
rabbitmq-plugins disable rabbitmq_prometheus
可以在 rabbitmq UI界面看到 启动监听的端口,默认15692端口
2、验证
windows:http://ip:15692/metrics
linux:curl 127.0.0.1:15692/metrics,非mq所在服务器需要把127.0.0.1改成你mq所在服务器的ip
4、默认配置
此导出器通过prometheus.*配置键支持以下选项:
prometheus.path 定义到处端点,默认是“/metrics”。
prometheus.tcp.* 控制匹配的HTTP监听器设置those used by the RabbitMQ HTTP API。
prometheus.ssl.* 控制匹配的TLS(HTTPS)监听器设置those used by the RabbitMQ HTTP API。
简单示例:
# these values are defaults
prometheus.path = /metrics
prometheus.tcp.port = 15692
这些配置可以通过rabbitmq的配置文件来修改,配置文件默认路径如下:
/etc/rabbitmq/rabbitmq.conf
插件地址:https://github.com/rabbitmq/rabbitmq-prometheus/blob/master/metrics.md
指标说明:https://github.com/rabbitmq/rabbitmq-prometheus/blob/master/metrics.md
5、加入prometheus
prometheus.yml
- job_name: "rabbitmq"
file_sd_configs:
- refresh_interval: 1m
files:
- /usr/local/prometheus/sd_config/rabbitmq.json
rabbitmq.json
[{
"targets": [
"10.62.197.160:15692"
],
"labels": {
"service": "水利水电rabbitmq主机",
"idc": "水利水电"
}
}]
二、第二种方式
1、下载rabbitmq_exproter安装包
1)本地下载后上传到linux服务器
https://github.com/kbudde/rabbitmq_exporter
https://www.rabbitmq.com/prometheus.html
2)直接在linux服务器上wget方式下载
cd /software
wget https://github.com/kbudde/rabbitmq_exporter/releases/download/v1.0.0-RC13/rabbitmq_exporter_1.0.0-RC13_linux_amd64.tar.gz
tar -zxvf rabbitmq_exporter_1.0.0-RC13_linux_amd64.tar.gz -C /usr/local/
cd /usr/local/
mv rabbitmq_exporter_1.0.0-RC13_linux_amd64 rabbitmq_exporter
2、将rabbitmq_exproter配置为系统服务
# 1、进入systemd目录
cd /usr/lib/systemd/system
# 2、创建文件
vim rabbitmq_exproter.service
# 添加如下内容
[Unit]
Description=https://www.rabbitmq.com/prometheus.html
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/rabbitmq_exporter/rabbitmq_exporter -config-file /usr/local/rabbitmq_exporter/config.example.json
[Install]
WantedBy=multi-user.target
# 生效系统systemd文件
systemctl daemon-reload
# 设置开机自启
systemctl enable rabbitmq_exporter
# 启动
systemctl start rabbitmq_exporter
# 查看状态
systemctl status rabbitmq_exporter
# 停止
systemctl stop rabbitmq_exporter
3、启动rabbitmq_exporter
# 后台启动
nohup /usr/local/rabbitmq_exporter/rabbitmq_exporter >> /usr/local/rabbitmq_exporter/rabbitmq_exporter.out 2>&1 &
# 指定端口
--web.listen-address=:9419
http://172.30.18.244:9419/metrics,默认端口为9419
4、添加 Prometheus 监控配置
# 进入 prometheus 文件夹
cd /usr/local/prometheus
# 编辑 prometheus 配置文件
vim prometheus.yml
# 添加如下内容
- job_name: 'rabbitmq_exporter'
static_configs:
- targets: ['192.168.0.102:9419']