Skip to content

Instantly share code, notes, and snippets.

@rajkrrsingh
Last active July 23, 2022 12:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rajkrrsingh/b4378a726d56f43dc5786dc3b73b4918 to your computer and use it in GitHub Desktop.
Save rajkrrsingh/b4378a726d56f43dc5786dc3b73b4918 to your computer and use it in GitHub Desktop.
Monitoring Kafka Broker JMX using jolokia JVM Agent
Download Jolokia JVM Agent from following location
https://jolokia.org/download.html
wget http://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/1.3.7/jolokia-jvm-1.3.7-agent.jar

mv jolokia-jvm-1.3.7-agent.jar agent.jar
here is the small shell script to get metrics you are intersted in
#!/bin/sh

url=`java -jar agent.jar start $1 | tail -1`

memory_url="${url}read/kafka.server:type=KafkaRequestHandlerPool,name=RequestHandlerAvgIdlePercent"
used=`wget -q -O - "${memory_url}/MeanRate" | grep MeanRate`
echo $used
java -jar agent.jar --quiet stop $1
we are good to run this and start seeing this messages (19876 is the pid for kafka broker)
./script1.sh 19876 
{"timestamp":1507308779,"status":200,"request":{"mbean":"kafka.server:name=RequestHandlerAvgIdlePercent,type=KafkaRequestHandlerPool","attribute":"MeanRate","type":"read"},"value":0.9999940178320261}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment