Monitor

你能够通过不同的方式去监控一个 Pulsar 集群。可以通过主题使用相关的指标和集群每个组件的总体健康指标,来衡量集群是否健康。

指标采集

你可以采集 broker、ZooKeeper、BookKeeper 的统计信息。

Borker 统计信息

You can collect Pulsar broker metrics from brokers and export the metrics in JSON format. The Pulsar broker metrics mainly have two types:

  • Destination dumps, which contain stats for each individual topic. You can fetch the destination dumps using the command below:

    1. bin/pulsar-admin broker-stats destinations
  • Broker metrics, which contain the broker information and topics stats aggregated at namespace level. You can fetch the broker metrics by using the following command:

    1. bin/pulsar-admin broker-stats monitoring-metrics

所有的指标都是每分钟更新一次。

The aggregated broker metrics are also exposed in the Prometheus format at:

  1. http://$BROKER_ADDRESS:8080/metrics/

ZooKeeper 统计信息

Pulsar 自带的本地 ZooKeeper 、配置存储服务器和客户端,都通过 Prometheus 暴露出详细统计信息。

  1. http://$LOCAL_ZK_SERVER:8000/metrics
  2. http://$GLOBAL_ZK_SERVER:8001/metrics

The default port of local ZooKeeper is 8000 and the default port of the configuration store is 8001. You can use a different stats port by configuring metricsProvider.httpPort in the conf/zookeeper.conf file.

BookKeeper 统计信息

你可以通过修改配置文件conf/bookkeeper.conf中的配置项statsProviderClass,来修改 BookKeeper 的统计框架。

The default BookKeeper configuration enables the Prometheus exporter. The configuration is included with Pulsar distribution.

  1. http://$BOOKIE_ADDRESS:8000/metrics

The default port for bookie is 8000. You can change the port by configuring prometheusStatsHttpPort in the conf/bookkeeper.conf file.

托管游标确认状态的统计信息

确认状态(acknowledgment state)首先会被持久化到 ledger 中。 当确认状态无法被持久化到 ledger 中时,它们将被持久化到 ZooKeeper。 要想跟踪确认状态的统计信息,你可以配置托管游标的相关指标。

  1. brk_ml_cursor_persistLedgerSucceed(namespace="", ledger_name="", cursor_name:"")
  2. brk_ml_cursor_persistLedgerErrors(namespace="", ledger_name="", cursor_name:"")
  3. brk_ml_cursor_persistZookeeperSucceed(namespace="", ledger_name="", cursor_name:"")
  4. brk_ml_cursor_persistZookeeperErrors(namespace="", ledger_name="", cursor_name:"")
  5. brk_ml_cursor_nonContiguousDeletedMessagesRange(namespace="", ledger_name="", cursor_name:"")

这些指标添加到了 Prometheus 界面,你可以在 Grafana 监控和检查相关统计信息。

Function 和连接器统计信息

你可以从 functions-worker 收集相关 Function worker 统计信息,并以 JSON 格式导出包括 Function worker JVM 指标在内的相关信息。

  1. pulsar-admin functions-worker monitoring-metrics

你可以从 functions-worker 收集 Function 和连接器的相关指标,并以 JSON 格式将它们导出。

  1. pulsar-admin functions-worker function-stats

整体汇总的 Function 和连接器指标都以如下方式暴露给 Prometheus。 你可以从 functions_worker.yml 文件中获取 FUNCTIONS_WORKER_ADDRESSWORKER_PORT

  1. http://$FUNCTIONS_WORKER_ADDRESS:$WORKER_PORT/metrics:

Prometheus 配置

你能够使用 prometheus 来采集 Pular 组件暴露出来的所有指标,并使用 Grafana 去展示这些指标。可以用这种方式来监控 Pulsar 集群。 For details, refer to Prometheus guide.

当 Pulsar 运行在裸机上时,你需要提供一个需要探测的节点列表。 当 Pulsar 运行在 Kubernetes 集群时,监控系统是自动启动的。 For details, refer to Kubernetes instructions.

仪表盘

When you collect time series statistics, the major problem is to make sure the number of dimensions attached to the data does not explode. 因此,只需要按照命名空间维度去采集时序指标,再做聚合。

Pulsar 主题维度监控面板

Pulsar Manager 提供了主题维度的监控面板。

Grafana

你能够使用 grafana 创建一个监控面板,底层的数据来源是在 Prometheus 里面。

When you deploy Pulsar on Kubernetes, a pulsar-grafana Docker image is enabled by default. You can use the docker image with the principal dashboards.

Enter the command below to use the dashboard manually:

  1. docker run -p3000:3000 \
  2. -e PROMETHEUS_URL=http://$PROMETHEUS_HOST:9090/ \
  3. apachepulsar/pulsar-grafana:latest

The following are some Grafana dashboards examples:

  • pulsar-grafana: 当 Pulsar 集群运行在 Kubernetes 时,用来展示 Prometheus 采集的指标项的 Grafana 面板。
  • apache-pulsar-grafana-dashboard: 不同 Pulsar 组件的 Grafana 监控面板模板集合。运行在 Kubernetes 和 本地机器时都可以用。

告警规则

您能够通过 Pulsar 环境设置告警规则。 想要配置 Apache Pulsar 的告警规则,请参考 Prometheus 告警规则 相关内容。