Prometheus 監控zookeeper使用jvm_exporter來採集數據,jvm_exporter是一個能夠配置抓取和暴露JMX目標的mBeans的收集器。java
cd /usr/local/zookeeper/prometheus
wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar
rules: # replicated Zookeeper - pattern: "org.apache.ZooKeeperService<name0=ReplicatedServer_id(\\d+)><>(\\w+)" name: "zookeeper_$2" - pattern: "org.apache.ZooKeeperService<name0=ReplicatedServer_id(\\d+), name1=replica.(\\d+)><>(\\w+)" name: "zookeeper_$3" labels: replicaId: "$2" - pattern: "org.apache.ZooKeeperService<name0=ReplicatedServer_id(\\d+), name1=replica.(\\d+), name2=(\\w+)><>(\\w+)" name: "zookeeper_$4" labels: replicaId: "$2" memberType: "$3" - pattern: "org.apache.ZooKeeperService<name0=ReplicatedServer_id(\\d+), name1=replica.(\\d+), name2=(\\w+), name3=(\\w+)><>(\\w+)" name: "zookeeper_$4_$5" labels: replicaId: "$2" memberType: "$3" # standalone Zookeeper - pattern: "org.apache.ZooKeeperService<name0=StandaloneServer_port(\\d+)><>(\\w+)" name: "zookeeper_$2" - pattern: "org.apache.ZooKeeperService<name0=StandaloneServer_port(\\d+), name1=InMemoryDataTree><>(\\w+)" name: "zookeeper_$2"
if [ "x$SERVER_JVMFLAGS" != "x" ] then JVMFLAGS="$SERVER_JVMFLAGS $JVMFLAGS" fi ## 新增javaagent JMX_DIR="/usr/local/zookeeper/prometheus" JVMFLAGS="$JVMFLAGS -javaagent:$JMX_DIR/jmx_prometheus_javaagent-0.3.1.jar=9505:$JMX_DIR/zookeeper.yml" if [ "x$2" != "x" ] then ZOOCFG="$ZOOCFGDIR/$2" fi
curl localhost:9505/metrics
apache
- job_name: 'zookeeper' static_configs: - targets: ['172.16.10.62:9505']
重啓prometheus,而後在Prometheus頁面中的Targets中就能看到新加入的zookeepercurl