重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
這篇文章主要為大家展示了“如何利用prometheus監控zookeeper”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“如何利用prometheus監控zookeeper”這篇文章吧。
為焉耆等地區用戶提供了全套網頁設計制作服務,及焉耆網站建設行業解決方案。主營業務為做網站、成都網站制作、焉耆網站設計,以傳統方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業、用心的態度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!官方介紹:主要有兩種方式,四字命令和jmx
https://zookeeper.apache.org/doc/r3.4.14/zookeeperAdmin.html#sc_zkCommands 其中最常用的三個stat、srvr、cons
Three of the more interesting commands: "stat" gives some general information about the server and connected clients, while "srvr" and "cons" give extended details on server and connections respectively.
$ echo srvr | nc svc-zk.o.svc.mhc.local 2181 Zookeeper version: 3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT Latency min/avg/max: 0/0/802 Received: 5833450 Sent: 6074801 Connections: 84 Outstanding: 0 Zxid: 0x2d9407 Mode: standalone Node count: 12977
使用四字命令對已經在生產運行的zookeeper監控起來比較方便,就是向zookeeper服務發送mntr之類的命令
具體實現參考:https://github.com/jiankunking/zookeeper_exporter
按照上述參考文檔構建鏡或者使用打好的鏡像 carlpett/zookeeper_exporter ,并啟動exporter
docker run -it -p 9141:9141 --name=zookeeper_exporter_m -d xxx.xxx.com/library/zookeeper_exporter:1.0.2 -zookeeper svc-zk.m.svc.uuu.local:2181 curl http://127.0.0.1:9141/metrics ...... # HELP zk_avg_latency Average latency of requests # TYPE zk_avg_latency gauge zk_avg_latency 0 # HELP zk_ephemerals_count Number of ephemeral nodes # TYPE zk_ephemerals_count gauge zk_ephemerals_count 2625 # HELP zk_max_file_descriptor_count Maximum number of open file descriptors # TYPE zk_max_file_descriptor_count counter zk_max_file_descriptor_count 1.048576e+06 # HELP zk_max_latency Maximum seen latency of requests # TYPE zk_max_latency gauge zk_max_latency 1 # HELP zk_min_latency Minimum seen latency of requests # TYPE zk_min_latency gauge zk_min_latency 0 # HELP zk_num_alive_connections Number of active connections # TYPE zk_num_alive_connections gauge zk_num_alive_connections 82 # HELP zk_open_file_descriptor_count Number of open file descriptors # TYPE zk_open_file_descriptor_count gauge zk_open_file_descriptor_count 107 # HELP zk_outstanding_requests Number of outstanding requests # TYPE zk_outstanding_requests gauge zk_outstanding_requests 0 # HELP zk_packets_received Number of packets received # TYPE zk_packets_received counter zk_packets_received 40 # HELP zk_packets_sent Number of packets sent # TYPE zk_packets_sent counter zk_packets_sent 40 # HELP zk_server_state Server state (leader/follower) # TYPE zk_server_state untyped zk_server_state{state="standalone"} 1 # HELP zk_up Exporter successful # TYPE zk_up gauge zk_up 1 # HELP zk_watch_count Number of watches # TYPE zk_watch_count gauge zk_watch_count 22108 # HELP zk_znode_count Number of znodes # TYPE zk_znode_count gauge zk_znode_count 13105 # HELP zookeeper_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which zookeeper_exporter was built. # TYPE zookeeper_exporter_build_info gauge zookeeper_exporter_build_info{branch="",goversion="go1.10.8",revision="",version=""} 1
prometheus配置內容添加如下配置,此處同時添加了自定義標簽env:
- job_name: zk-u static_configs: - targets: - 172.21.11.101:9141 labels: env: u - job_name: zk-m static_configs: - targets: - 172.21.11.101:9142 labels: env: m - job_name: zk-h static_configs: - targets: - 172.21.11.101:9143 labels: env: h - job_name: zk-c static_configs: - targets: - 172.21.11.101:9144 labels: env: c
reload生效配置
curl -XPOST http://prometheus:9090/-/reload
prometheus頁面上查看target:
grafana展示:
是利用jvm_exporter暴露指標,參考prometheus官方jmx_exporter https://github.com/prometheus/jmx_exporter
jvm-exporter從基于jvm的應用讀取jmx數據并以http的方式暴露給prometheus抓取
jmx是一種常用的技術,輸出運行中應用的狀態信息,并且可以控制它(例如用jmx觸發gc)
jvm-exporter是用jmx apis收集app和jvm metrics的Java應用,以Java agent方式運行在同一個jvm里面。
jvm-exporter用Java寫的,以jar包的方式發布,下載地址
有一個ansible role(https://github.com/alexdzyoba/ansible-jmx-exporter),配置文件包含將JMX MBean重寫為Prometheus展示格式度量標準的規則。基本上它是將MBeans字符串轉換為Prometheus字符串的regexp集合。
zookeeper是很多系統的關鍵組成部分,例如Hadoop, Kafka and Clickhouse,因此監控是必不可少的。
zookeeper啟動的時候傳入參數啟用,不需要開啟jmx
$ cat java.env export SERVER_JVMFLAGS="-javaagent:/root/jmx_prometheus_javaagent-0.12.0.jar=7070:/root/config.yaml $SERVER_JVMFLAGS"
查看啟動日志并檢查結果:
$ netstat -tlnp | grep 7070 tcp 0 0 0.0.0.0:7070 0.0.0.0:* LISTEN 892/java $ curl -s localhost:7070/metrics | head # HELP jvm_threads_current Current thread count of a JVM # TYPE jvm_threads_current gauge jvm_threads_current 16.0 # HELP jvm_threads_daemon Daemon thread count of a JVM # TYPE jvm_threads_daemon gauge jvm_threads_daemon 12.0 # HELP jvm_threads_peak Peak thread count of a JVM # TYPE jvm_threads_peak gauge jvm_threads_peak 16.0 # HELP jvm_threads_started_total Started thread count of a JVM
With jmx-exporter you can scrape the metrics of running JVM applications. jmx-exporter runs as a Java agent (inside the target JVM) scrapes JMX metrics, rewrite it according to config rules and exposes it in Prometheus exposition format.
基于官方zookeeper的github倉庫,修改官方dockerfile以加入啟動參數
下面鏈接是我修改后的,親測可用
https://github.com/weifan01/zookeeper-docker/tree/master/3.4.14
構建好的zk-3.4.14版本鏡像: docker pull 3070656869/zookeeper:3.4.14-jvm-exporter
啟動OK后,訪問8080端口查看結果
參考官方文檔:https://github.com/prometheus/jmx_exporter
git clone https://github.com/prometheus/jmx_exporter.git cd jmx_exporter mvn package
#修改配置文件example_configs/httpserver_sample_config.yml #修改啟動腳本里面的監聽地址和端口 sh run_sample_httpserver.sh
我測試配置如下:
$ cat http_server_config.yaml --- # jmx地址和端口 hostPort: 172.21.10.248:6666 username: password: rules: # replicated Zookeeper - pattern: "org.apache.ZooKeeperService<>(\\w+)" name: "zookeeper_$2" - pattern: "org.apache.ZooKeeperService <>(\\w+)" name: "zookeeper_$3" labels: replicaId: "$2" - pattern: "org.apache.ZooKeeperService <>(\\w+)" name: "zookeeper_$4" labels: replicaId: "$2" memberType: "$3" - pattern: "org.apache.ZooKeeperService <>(\\w+)" name: "zookeeper_$4_$5" labels: replicaId: "$2" memberType: "$3" # standalone Zookeeper - pattern: "org.apache.ZooKeeperService <>(\\w+)" name: "zookeeper_$2" - pattern: "org.apache.ZooKeeperService <>(\\w+)" name: "zookeeper_$2"
啟動:
java -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=6667 -jar jmx_prometheus_httpserver-0.12.1-SNAPSHOT-jar-with-dependencies.jar 172.21.10.248:6668 http_server_config.yaml
訪問:
以上是“如何利用prometheus監控zookeeper”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!
另外有需要云服務器可以了解下創新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。