Skip to content

Prometheus 监控集成

Zeze 通过 PrometheusCounter 实现与 Prometheus 监控系统的集成,基于 prometheus-metrics-core 库提供丰富的运行时指标。通过 HTTP 端点暴露标准 metrics 格式,可直接接入 Prometheus Server 或 Grafana Dashboard。

pom.xml 中引入 prometheus-metrics-coreprometheus-metrics-exporter-httpserver(Zeze 已声明为 provided scope)。

通过 PrometheusCounter.addHttpHandler 将 metrics 端点注册到 Zeze 的 HTTP 服务:

var httpServer = new HttpServer();
httpServer.start(netty, 9090);
PrometheusCounter.addHttpHandler(httpServer);

这将注册两个端点:

路径说明
/metricsPrometheus 指标抓取端点
/healthy健康检查端点,返回 Exporter is healthy.

通过 JVM 系统属性指定 Counter 实现类(默认已启用 PrometheusCounter):

-DZezeCounter=Zeze.Util.PrometheusCounter

设为空或 null 可完全禁用指标收集。

ZezeCounter 是 Zeze 的指标抽象接口,PrometheusCounter 是其 Prometheus 实现。以下指标自动收集:

指标名类型标签说明
procedure_startedCounterprocedure事务启动次数
procedure_completedCounterprocedure, result_code事务完成次数(含结果码)
procedure_duration_secondsHistogramprocedure, result_code事务执行耗时分布
procedure_redoCounterprocedure事务重做次数
procedure_redo_and_release_lockCounterprocedure重做并释放锁次数
procedure_many_locksHistogramprocedure事务锁定数量分布
指标名类型标签说明
protocol_recv_bytesCounterprotocol接收字节数
protocol_duration_secondsHistogramprotocol协议处理耗时
protocol_sendCounterprotocol发送次数
protocol_send_bytesCounterprotocol发送字节数
指标名类型标签说明
database_table_operationCountertable, operation表操作计数(readLock, writeLock, storageGet, acquireShare, acquireModify 等)
指标名类型标签说明
service_output_buffer_bytesHistogramservice输出缓冲区大小分布
service_recvCounterservice服务接收计数
service_recv_bytesCounterservice服务接收字节数
service_sendCounterservice服务发送计数
service_send_bytesCounterservice服务发送字节数
service_send_raw_bytesCounterservice服务发送原始字节数
scrape_configs:
- job_name: 'zeze'
scrape_interval: 15s
static_configs:
- targets: ['localhost:9090']
  1. 事务延迟:关注 procedure_duration_seconds 的 P99 分位数,发现慢事务。
  2. 重做率procedure_redo / procedure_started 的比率反映锁冲突程度。
  3. 协议吞吐protocol_recv_bytesprotocol_send_bytes 监控网络负载。
  4. 缓冲区压力service_output_buffer_bytes 异常增长可能表示网络瓶颈。
  5. 缓存同步database_table_operation 中的 acquireShare/acquireModify/acquireInvalid 反映 GlobalCacheManager 的负载。

通过 ZezeCounter 接口可创建自定义指标:

var counter = ZezeCounter.instance.allocCounter("my_custom_counter");
counter.inc();
var labeledCounter = ZezeCounter.instance.allocLabeledCounterCreator(
"my_labeled_counter", "label1", "label2");
labeledCounter.labelValues("value1", "value2").inc();