kube-prometheus监控RabbitMQ 指标
方案
通过 Prometheus
找到 Exporter 可以对第三方服务导出为 Prometheus 指标。
也可以使用 RabbitMQ官网方案插件进行监控,本次记录是按照RabbitMQ官网方案进行。
操作步骤
开启 RabbitMQ_Prometheus 插件
如果 rabbitmq_prometheus
已经开启可以跳过这一步,执行:rabbitmq-plugins enable rabbitmq_prometheus
查看RabbitMQ Prometheus 指标
具体指标的查看 RabbitMQ 指标 官网详细介绍
http://localhost:15692/metrics
因k8s部署,只开放了15672/5672
未对15692
开放端口,因此需要对其开放
apiVersion: v1
kind: Service
metadata:
name: rabbitmq-export-svc
namespace: tools
labels:
type: rabittmq-exporter
spec:
type: ClusterIP
ports:
- name: http-metrics
protocol: TCP
port: 15692
targetPort: 15692
selector:
app: rabbitmq-single
name: rabbitmq-single
配置 Prometheus Service Monitor
rabbitmq-sm.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app: rabbitmq-sm
name: rabbitmq-sm
namespace: monitoring
spec:
endpoints:
- port: http-metrics
interval: 30s
namespaceSelector:
any: true
selector:
matchLabels:
type: rabittmq-exporter
查看 Prometheus Status Targets
说明已经成功监听到 RabbitMQ Exporter
了。
配置 Grafana Dashboard 页面
参考:https://github.com/rabbitmq/rabbitmq-server/tree/main/deps/rabbitmq_prometheus/docker/grafana/dashboards
或者使用:https://grafana.com/grafana/dashboards/10991-rabbitmq-overview/
告警规则配置
参考:https://www.rabbitmq.com/prometheus.html#detailed-endpoint
后续进行细化项告警
rabbitmq-rules.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
prometheus: k8s
role: alert-rules
name: redis-rules
namespace: monitoring
spec:
groups:
- name: RabbitMQAlerts
rules:
- alert: RabbitMQTooManyConnections
expr: rabbitmq_connections > 500
for: 5m
labels:
severity: critical
annotations:
summary: "RabbitMQ has too many connections"
description: "The RabbitMQ server has {{ $value }} connections, which is above the threshold of 500 connections."