How to monitor JMX metrics of Kafka broker on command line?
Asked Answered
T

2

12

A Kafka cluster can be monitored in granular detail via the JMX metrics it exposes. Usually an external GUI or application like jconsole needs to be hooked up to a broker's exposed JMX_PORT in order to view these metrics.

Is there a way that I can view a broker's JMX metrics in an SSH session, via STDOUT? Is there a native Kafka command that I can run to view these metrics?

Tirza answered 19/1, 2017 at 22:5 Comment(1)
This is not specific to Kafka, but here is a prior answer with a lot of options for command line JMX utilities. #1751630Midge
M
6

Download the jar located here:

https://sourceforge.net/projects/cyclops-group/files/jmxterm/1.0-alpha-4/

On the machine, then run:

wget https://sourceforge.net/projects/cyclops-group/files/jmxterm/1.0-alpha-4/ -o jmxterm.jar

java -jar jmxterm.jar

>open localhost:$jmx_port

Help will give you what you need after that :)

Save this jar somewhere useful, I use it nearly every day.

Makell answered 23/1, 2017 at 15:1 Comment(1)
This is giving "#RuntimeIOException: Runtime IO exception: Service URL must start with service:jmx:" though I am not using the same jar but "jmxterm-1.0.2-uber.jar"Mat
B
21

Use kafka.tools.JmxTool.

Assuming you have enabled JMX on your broker on the default port of 9999, you can simply run this example command to print out jmx metrics for BrokerTopics via STDOUT

$ ./bin/kafka-run-class.sh kafka.tools.JmxTool \
  --object-name kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec
Trying to connect to JMX url: service:jmx:rmi:///jndi/rmi://:9999/jmxrmi.
"time","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:Count","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:EventType","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:FifteenMinuteRate","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:FiveMinuteRate","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:MeanRate","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:OneMinuteRate","kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec:RateUnit"
1567587563143,0,messages,0.0,0.0,0.0,0.0,SECONDS
1567587565148,0,messages,0.0,0.0,0.0,0.0,SECONDS
1567587567150,0,messages,0.0,0.0,0.0,0.0,SECONDS
...

JmxTool prints out JMX metrics every --reporting-interval option.

--reporting-interval <Integer: ms>

Interval (in millis) with which to poll jmx stats

Default: 2000 (2 seconds)

Value of -1 is equivalent to --one-time true

Borkowski answered 7/7, 2017 at 21:56 Comment(0)
M
6

Download the jar located here:

https://sourceforge.net/projects/cyclops-group/files/jmxterm/1.0-alpha-4/

On the machine, then run:

wget https://sourceforge.net/projects/cyclops-group/files/jmxterm/1.0-alpha-4/ -o jmxterm.jar

java -jar jmxterm.jar

>open localhost:$jmx_port

Help will give you what you need after that :)

Save this jar somewhere useful, I use it nearly every day.

Makell answered 23/1, 2017 at 15:1 Comment(1)
This is giving "#RuntimeIOException: Runtime IO exception: Service URL must start with service:jmx:" though I am not using the same jar but "jmxterm-1.0.2-uber.jar"Mat

© 2022 - 2024 — McMap. All rights reserved.