生产环境里 ZooKeeper 的监控怎么接?3.6 之后自带 Prometheus 指标端点,不需要额外的 exporter。这篇配置它、抓一次、看有哪些指标,再看 GC 日志怎么和它们配合。
GET http://127.0.0.1:7390/metrics → 200,Content-Type: text/plain; version=0.0.4; charset=utf-8,共 15753 行,15397 个样本
不同的指标名共 302 个;前 12 个: ['add_dead_watcher_stall_time', 'approximate_data_size', 'auth_failed_count', 'avg_latency', 'bytes_received_count', 'close_session_prep_time', 'close_session_prep_time_count', 'close_session_prep_time_sum', 'cnxn_closed_without_zk_server_running', 'commit_commit_proc_req_queued', 'commit_commit_proc_req_queued_count', 'commit_commit_proc_req_queued_sum']
指标名前缀分类: {'znode': 1, 'num_alive': 1, 'jvm_': 28, 'process_': 4, 'fsynctime': 3, 'readlatency': 3, 'updatelatency': 3, 'packets': 2, 'watch': 2, 'outstanding': 4, 'request': 9, 'proposal': 10}这个端点没有认证,所以只绑定 127.0.0.1(metricsProvider.httpHost)。要给 Prometheus 抓取,应当放在内网并用防火墙限制来源(第 67 篇谈四字命令的暴露面,同样的道理)。
znode_count 5005.0
num_alive_connections 1.0
watch_count 0.0
outstanding_requests 0.0
packets_received 5002.0
packets_sent 5002.0
fsynctime_count 136.0
jvm_gc_collection_seconds_count{gc="G1 Young Generation",} 41.0
jvm_gc_collection_seconds_count{gc="G1 Old Generation",} 1.0[2026-10-01T12:01:49.633+0800][0.006s][info][gc] Using G1 [2026-10-01T12:01:49.797+0800][0.170s][info][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) [2026-10-01T12:01:49.797+0800][0.170s][info][gc,task ] GC(0) Using 2 workers of 9 for evacuation [2026-10-01T12:01:49.799+0800][0.172s][info][gc ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 14M->3M(34M) 1.755ms JVM 内部指标 jvm_gc_collection_seconds_* 与 GC 日志的关系:前者是累计次数 / 耗时(适合告警),后者是每一次的细节(适合排查)。