sequence

This paper mainly studies how to use JMxtrans + InfluxDB + Granfa to monitor ZooKeeper

Configuration zookeeper JMX

Add zookeeper-env.sh in the conf directory and run the chmod +x command to grant the execution permission

JMXLOCALONLY=false
JMXDISABLE=false
JMXPORT=8999
JMXAUTH=false
JMXSSL=false
Copy the code
  • Specify JMXPORT as 8999

Influence XDB and Grafana were established

This is built using Docker as follows

docker network create monitoring-network
docker run -d-p 8083:8083 -p 8086:8086 \ --net monitoring-network \ --name Influxdb \ influxDB :1.5.4 curl -POST http://192.168.99.100:8086/query - data - urlencode"q=CREATE DATABASE zookeeper"
docker run -d-p 001:00 -- NET monitoring-network --name grafana grafana/grafana:5.2.4 curl'http://admin:[email protected]:3000/api/datasources' -X POST \
-H 'Content-Type: application/json; charset=UTF-8' \
--data-binary '{" name ":" the influx ", "type" : "influxdb", "url" : "http://192.168.99.100:8086", "access":"proxy","isDefault":true,"database":"zookeeper","user":"admin","password":"admin"}'
Copy the code
  • Create a Monitor-network, connect the InfluxDB in docker to grafana, and then use the REST API to create the ZooKeeper database
  • Create grafana and specify NET as monitor-Network, then configure the data source using the REST API

Jmxtrans configuration

  • Download jmxtrans
wget http://central.maven.org/maven2/org/jmxtrans/jmxtrans/270/jmxtrans-270-all.jar
Copy the code
  • Downloading the Execution script
wget -q https://raw.githubusercontent.com/jmxtrans/jmxtrans/master/jmxtrans/jmxtrans.sh
chmod +x jmxtrans.sh
Copy the code
  • Configuration to zookeeper. Json
{
  "servers": [{"port": 8999,
      "host": "localhost"."alias": "zk"."queries": [{"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id*"."attr": [
            "QuorumSize"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id*,name1=replica*,name2=*"."attr": [
            "MaxClientCnxnsPerHost"."MaxRequestLatency"."AvgRequestLatency"."MinRequestLatency"."MaxSessionTimeout"."MinSessionTimeout"."OutstandingRequests"."PacketsReceived"."PacketsSent"."PendingRevalidationCount"."TickTime"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id*,name1=replica*,name2=*,name3=InMemoryDataTree"."attr": [
            "NodeCount"."WatchCount"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id*,name1=replica*,name2=*,name3=Connections,name4=*,name5=*"."resultAlias": "Clients"."attr": [
            "AvgLatency"."LastLatency"."MaxLatency"."MinLatency"."OutstandingRequests"."PacketsReceived"."PacketsSent"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "org.apache.ZooKeeperService:name0=StandaloneServer_port*"."resultAlias": "Clients"."attr": [
            "AvgLatency"."LastLatency"."MaxLatency"."MinLatency"."OutstandingRequests"."PacketsReceived"."PacketsSent"."NumAliveConnections"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "java.lang:type=Memory"."resultAlias": "Memory"."attr": [
            "HeapMemoryUsage"."NonHeapMemoryUsage"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "java.lang:type=OperatingSystem"."resultAlias": "Process"."attr": [
            "OpenFileDescriptorCount"."ProcessCpuLoad"] {},"outputWriters": [{"@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory"."url" : "http://192.168.99.100:8086/"."database" : "zookeeper"."username" : "admin"."password" : "admin"}]."obj": "java.lang:type=Threading"."resultAlias": "Threading"."attr": [
            "ThreadCount"]}],"numQueryThreads": 2}]}Copy the code

It will be automatically loaded in the same directory as the jmxtrans.sh script

  • Start the
JAR_FILE=jmxtrans-270-all.jar ./jmxtrans.sh start
Copy the code
  • Log Output Instance
2018-10-04 11:28:30 [main] level org.quartz.impl.StdSchedulerFactory [StdSchedulerFactory.java:1179] - Using default implementation for ThreadExecutor
2018-10-04 11:28:30 [main] level org.quartz.core.SchedulerSignalerImpl [SchedulerSignalerImpl.java:60] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 2018-10-04 11:28:30 [main] level org.quartz.core.QuartzScheduler [QuartzScheduler. Java :229] -Quartz Scheduler V. 1.8.6 created. 2018-10-04 11:28:30 [main] Level org.quartz.simpl.RAMJobStore [RAMJobStore.java:139] - RAMJobStore initialized. 2018-10-04 11:28:30 [main] level Org. Quartz. Core. QuartzScheduler [QuartzScheduler. Java: 255] - the Scheduler meta - data: quartz Scheduler (v1.8.6)'ServerScheduler' with instanceId 'Mars.local1538623710548'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - whichdoes not support persistence. and is not clustered. 2018-10-04 11:28:30 [main] level org.quartz.impl.StdSchedulerFactory  [StdSchedulerFactory.java:1324] - Quartz scheduler'ServerScheduler'initialized from an externally opened InputStream. 2018-10-04 11:28:30 [main] level org.quartz.impl.StdSchedulerFactory [StdSchedulerFactory.java:1328] - Quartz scheduler version: 1.8.6 11:28:30 2018-10-04 [main] level org. Quartz. Core. The QuartzScheduler [QuartzScheduler. Java: 2267] - JobFactoryset to: com.googlecode.jmxtrans.guice.GuiceJobFactory@263f04ca
2018-10-04 11:28:30 [main] level com.googlecode.jmxtrans.JmxTransformer [JmxTransformer.java:177] - Starting Jmxtrans on : .
2018-10-04 11:28:30 [main] level org.quartz.core.QuartzScheduler [QuartzScheduler.java:519] - Scheduler ServerScheduler_$_Mars.local1538623710548 started. 2018-10-04 11:28:30 [main] level com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory  [InfluxDbWriterFactory.java:121] - Result Tags to writeset to: [ResultAttribute(name=typeName), ResultAttribute(name=objDomain), ResultAttribute(name=className), ResultAttribute(name=attributeName)]
2018-10-04 11:28:30 [main] level com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory [InfluxDbWriterFactory.java:102] - Connecting to url: http://192.168.99.100:8086/ as: username: admin
2018-10-04 11:28:31 [main] level com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory [InfluxDbWriterFactory.java:121] - Result Tags to write set to: [ResultAttribute(name=typeName), ResultAttribute(name=objDomain), ResultAttribute(name=className), ResultAttribute(name=attributeName)]
Copy the code

Example Query the influxDB data

docker exec- It InfluxDB Influx Connected to http://localhost:8086 version 1.5.4 InfluxDB shell version: 1.5.4 > use zookeeper Using database zookeeper > show MEASUREMENTS name: measurements name ---- Clients Memory Process Threading > show series from"Memory"
key
---
Memory,attributeName=HeapMemoryUsage,className=sun.management.MemoryImpl,hostname=zk,objDomain=java.lang,typeName=type\=Memory
Memory,attributeName=NonHeapMemoryUsage,className=sun.management.MemoryImpl,hostname=zk,objDomain=java.lang,typeName=type\=Memory
Copy the code
  • Run the select * from “Memory” command to view specific indicator data
  • Once the query has data, you can configure visualization on Grafana and then monitor it

summary

For zooKeeper, Kafka and other applications, JMX is built in, so the monitoring can be collected and converted through JMxtrans, and then exported to InfluxDB, Graphite, Prometheus, etc. Finally, visualization and monitoring alarm can be performed through Grafana.

doc

  • jmxtrans
  • jmxtrans-270-all.jar
  • How do i enable remote jmx with port in zookeeper zkServer.cmd
  • Monitoring Apache Kafka with Grafana / InfluxDB via JMX