使用 Prometheus 和 Grafana 进行监控

https://www.rabbitmq.com/prometheus.html

当 RabbitMQ 与 Prometheus 和 Grafana 集成时,RabbitMQ 概览仪表板如下所示:

统一集群名称

第一步是给 RabbitMQ 集群起一个描述性的名称,以便与其他集群区分开来。

要查找集群的当前名称,请使用

rabbitmq-diagnostics -q cluster_status

可以针对任何集群节点执行此命令。如果当前集群名称独特且合适,请跳过本段的其余部分。要更改集群的名称,请运行以下命令(此处使用的名称只是示例):

rabbitmqctl -q set_cluster_name rabbitmq_cluster

启动 RabbitMQ 指标采集插件

启用 rabbitmq_prometheus

接下来,在所有节点上启用 rabbitmq_prometheus 插件:

rabbitmq-plugins enable rabbitmq_prometheus

输出将类似于:

rabbitmq-plugins enable rabbitmq_prometheus

Enabling plugins on node rabbit@ed9618ea17c9:
rabbitmq_prometheus
The following plugins have been configured:
  rabbitmq_management_agent
  rabbitmq_prometheus
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@ed9618ea17c9...
The following plugins have been enabled:
  rabbitmq_management_agent
  rabbitmq_prometheus
  rabbitmq_web_dispatch

started 3 plugins.

要确认 RabbitMQ 现在以 Prometheus 格式公开指标,请使用curl或类似方式获取前几行:

curl -s localhost:15692/metrics | head -n 3
# TYPE erlang_mnesia_held_locks gauge
# HELP erlang_mnesia_held_locks Number of held locks.
erlang_mnesia_held_locks{node="rabbit@65f1a10aaffa",cluster="rabbit@65f1a10aaffa"} 0

请注意,RabbitMQ 在专用 TCP 端口(默认情况下为15692)上公开指标。

启用 rabbitmq_stream
rabbitmq-plugins enable rabbitmq_stream

Prometheus 配置

修改 prometheus.yml,新增 RabbitMQ 指标采集配置:

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  - job_name: "rabbitmq_cluster"

    # metrics_path defaults to '/metrics'
    static_configs:
      - targets: ["192.168.3.73:15692","192.168.3.74:15692","192.168.3.75:15692","192.168.3.93:15692"]

Grafana 配置

RabbitMQ-Overview

前往 Grafana 网站查看官方 RabbitMQ Grafana 仪表板列表。

https://grafana.com/grafana/dashboards/10991-rabbitmq-overview/

选择 RabbitMQ-Overview 仪表板。

单击下载 JSON链接或复制仪表板 ID。

RabbitMQ-Stream

在 Grafana 导入 RabbitMQ-Stream 仪表板 :

https://grafana.com/grafana/dashboards/14798-rabbitmq-stream/

RabbitMQ-Quorum-Queues-Raft

在 Grafana 导入 RabbitMQ-Quorum-Queues-Raft 仪表板 :

https://grafana.com/grafana/dashboards/11340-rabbitmq-quorum-queues-raft/

作者:Jeebiz  创建时间:2023-05-05 11:03
最后编辑:Jeebiz  更新时间:2024-11-01 10:06