jmxterm is an excellent tool to poke mbeans. It is basically an interactive terminal-based JMX client. It is especially useful for scripting.
Interactive mode
It comes with help:
java -jar jmxterm-1.0-alpha-4-uber.jar Welcome to JMX terminal. Type "help" for available commands. $>help #following commands are available to use: about - Display about page bean - Display or set current selected MBean. beans - List available beans under a domain or all domains bye - Terminate console and exit close - Close current JMX connection domain - Display or set current selected domain. domains - List all available domain names exit - Terminate console and exit get - Get value of MBean attribute(s) help - Display available commands or usage of a command info - Display detail information about an MBean jvms - List all running local JVM processes open - Open JMX session or display current connection option - Set options for command session quit - Terminate console and exit run - Invoke an MBean operation set - Set value of an MBean attribute $>help beans usage: beans [-d <val>] [-h] List available beans under a domain or all domains -d,--domain <val> Name of domain under which beans are listed -h,--help Display usage Without -d option, current select domain is applied. If there's no domain specified, all beans are listed. Example: beans beans -d java.lang
Here is an example of connecting to an existing JVM and querying for a specific bean:
$>open 10167 $>info -b kafka.server:name=TotalFetchRequestsPerSec,topic=topicG,type=BrokerTopicMetrics #mbean = kafka.server:name=TotalFetchRequestsPerSec,topic=topicG,type=BrokerTopicMetrics #class name = com.yammer.metrics.reporting.JmxReporter$Meter # attributes %0 - Count (long, r) %1 - EventType (java.lang.String, r) %2 - FifteenMinuteRate (double, r) %3 - FiveMinuteRate (double, r) %4 - MeanRate (double, r) %5 - OneMinuteRate (double, r) %6 - RateUnit (java.util.concurrent.TimeUnit, r) # operations %0 - javax.management.ObjectName objectName() #there's no notifications $>get -s -b kafka.server:name=TotalFetchRequestsPerSec,topic=topicG,type=BrokerTopicMetrics OneMinuteRate #mbean = kafka.server:name=TotalFetchRequestsPerSec,topic=topicG,type=BrokerTopicMetrics: 7.960856160430041
(You can use the domain command to set the domain to avoid having to type out the fully qualified object name.)
Non-interactive (batch) mode
Same as above example, but non-interactive.
$ cat jmxcommands open 10167 get -s -b kafka.server:name=TotalFetchRequestsPerSec,topic=topicG,type=BrokerTopicMetrics OneMinuteRate close $ java -jar jmxterm-1.0-alpha-4-uber.jar -v silent -n < jmxcommands 7.973832278363945
If you have a JMX URI at hand, you can also poke remote mbeans:
$ java -jar jmxterm-1.0-alpha-4-uber.jar -l <JMX URI> -v silent -n < jmxcommands