radiantone/zk-exporterzk-exporter是一款用于将ZooKeeper的mntr统计信息转换为Prometheus格式的导出工具。它能够采集ZooKeeper的关键指标,方便通过Prometheus进行监控和告警。其中,zk_followers、zk_synced_followers和zk_pending_syncs指标仅在集群领导者节点上可用。
mntr命令输出转换为Prometheus可识别的指标格式1. ZooKeeper配置
从ZooKeeper v3.4.10开始,需要将mntr命令加入白名单。修改ZooKeeper配置文件zoo.cfg:
bashecho "4lw.commands.whitelist=mntr" >> /path/to/zoo.cfg # 重启ZooKeeper使配置生效 /path/to/zookeeper/bin/stop_zookeeper.sh /path/to/zookeeper/bin/start_zookeeper.sh
2. 命令行参数
警告:自v0.1.10版本起,指定目标ZooKeeper主机的参数已变更,使用时请注意。
Usage of zookeeper-exporter: -listen string 监听地址 (默认 "0.0.0.0:9141") -location string 指标路径 (默认 "/metrics") -timeout int 连接ZooKeeper的超时时间(秒)(默认 30) -zk-hosts string ZooKeeper服务器列表,逗号分隔,例如 '10.0.0.1:2181,10.0.0.2:2181' -zk-tls-auth bool 是否启用ZooKeeper TLS客户端认证 (默认 false) -zk-tls-auth-cert string TLS客户端认证证书路径(当-zk-tls-auth为true时必填) -zk-tls-auth-key string TLS客户端认证密钥路径(当-zk-tls-auth为true时必填)
3. 环境变量
| 变量名 | 默认值 | 描述 |
|---|---|---|
| ZK_CONN | - | (必填,否则指标服务器不启动)ZooKeeper节点连接字符串 |
| FLUENTD_ENABLE | - | 是否启用Fluentd日志流 |
| FLUENTD_CONF | - | (启用Fluentd时必填)Fluentd配置文件路径,需挂载到/fluentd/etc/fluent.conf |
| ELASTICSEARCH_HOST | - | (启用日志流到Elasticsearch时必填)Elasticsearch主机 |
| ELASTICSEARCH_PORT | 9200 | Elasticsearch端口 |
| PUSH_MODE | false | 是否启用推送模式,设为true启用 |
| PUSHGATEWAY_URI | - | Prometheus Pushgateway端点(如 [***]) |
| PUSH_METRICS_CRON | * * * * * | 推送指标的CRON表达式 |
| JOB_NAME | fid-targets | 推送时设置的抓取任务名称 |
| INSTANCE_NAME | $HOSTNAME | 推送时设置的实例名称 |
指标默认在9095端口的
/metrics路径提供 ZKExporter容器需要访问ZooKeeper日志文件:/opt/radiantone/rli-zookeeper-external/zookeeper/logs/zookeeper.log
4. Docker Compose示例
仅指标采集
yamlzkexp-0: image: radiantone/zk-exporter hostname: "zkexp-0" privileged: true environment: ZK_CONN: "zk-0:2181" # ZooKeeper连接字符串 ports: - 9095:9095 # 指标端口 volumes: - zk-0:/opt/radiantone # 挂载ZooKeeper数据目录 networks: zk-net: aliases: - zkexp-0
指标采集+Fluentd(默认Elasticsearch配置)
yamlzkexp-0: image: radiantone/zk-exporter hostname: "zkexp-0" privileged: true environment: ZK_CONN: "zk-0:2181" FLUENTD_ENABLE: "true" # 启用Fluentd FLUENTD_CONF: "/fluentd/etc/fluent.conf" ELASTICSEARCH_HOST: "elasticsearch" # Elasticsearch主机 ELASTICSEARCH_PORT: "9200" # Elasticsearch端口 ports: - 9095:9095 volumes: - zk-0:/opt/radiantone networks: zk-net: aliases: - zkexp-0
指标采集+Fluentd(自定义配置)
yamlzkexp-0: image: radiantone/zk-exporter hostname: "zkexp-0" privileged: true environment: ZK_CONN: "zk-0:2181" FLUENTD_ENABLE: "true" FLUENTD_CONF: "/fluentd/etc/fluent.conf" # 自定义配置路径 ports: - 9095:9095 volumes: - zk-0:/opt/radiantone - ./fluent.conf:/fluentd/etc/fluent.conf # 挂载自定义Fluentd配置 networks: zk-net: aliases: - zkexp-0
推送模式+Fluentd(默认Elasticsearch配置)
yamlzkexp-0: container_name: "zkexp-0" build: . hostname: "zkexp-0" privileged: true environment: PUSH_MODE: "true" # 启用推送模式 PUSHGATEWAY_URI: "[***]" # Pushgateway地址 ZK_CONN: "zk-0:2181" FLUENTD_ENABLE: "true" FLUENTD_CONF: "/fluentd/etc/fluent.conf" ELASTICSEARCH_HOST: "elasticsearch" ELASTICSEARCH_PORT: "9200"
5. 启动与停止
使用docker-compose管理ZooKeeper集群和exporter:
bash# 启动集群和exporter docker-compose up -d # 停止并清除容器 docker-compose down -v
6. Grafana仪表盘
推荐使用Grafana仪表盘监控指标:ZooKeeper Exporter Dashboard

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
manifest unknown
no matching manifest(架构)
TLS 证书失败
DNS 超时
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务