How to Read JMX Statistics via The Shell

Java Management Extensions (JMX) is a Java technology that supplies tools for managing and monitoring applications, system objects, and devices. Apigee components Management Server, Router, Message Processor, Qpid and Postgres can be monitored using JMX. Mostly, JMX statistics are viewed using UI based tools such as JConsole, and VisualVM. However, in some situations we would need to access JMX statistics via the shell. In this article I will explain how to enable JMX in Apigee Message Processor and check statistics via a shell command.

Prerequisites

How to Configure JMX in Message Processor

1. SSH into a Message Processor host

2. Add following JMX configuration parameters to the exec $JAVA command in /opt/apigee/edge-message-processor/bin/start bash script after the -Ddata.dir=$data_dir parameter:

-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1101 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false

Once added the exec $JAVA command may look as following:

# Launching java
exec $JAVA -classpath "$classpath" -Xms$min_mem -Xmx$max_mem $xx_opts -Djava.security.auth.login.config=$conf_path/jaas.config -Dinstallation.dir=$install_dir $sys_props -Dconf.dir=$conf_path -Ddata.dir=$data_dir \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1101 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
$ext_jvm_opts $* $debug_options com.apigee.kernel.MicroKernel

3. Now, restart Message Processor service:

apigee-service edge-message-processor restart

4. Check whether the JMX socket has started:

netstat -anp | grep LISTEN | grep 1101
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:1101            0.0.0.0:*               LISTEN      179007/java

How to Read JMX Statistics via the Shell

1. Download the latest stable jmxterm JAR file from the following releases page to the /tmp directory of the Message Processor: https://github.com/jiaqi/jmxterm/releases.

For an example:

cd /tmp
wget https://github.com/jiaqi/jmxterm/releases/download/v1.0.1/jmxterm-1.0.1-uber.jar

2. Start jmxterm console by executing below command:

java -jar jmxterm-1.0.1-uber.jar

3. Open a JMX connection to the Message Processor:

$>open localhost:1101

If everything goes well, the following output will be printed:

#Connection to localhost:1101 is opened

4. Execute the below command to list all JMX beans available in the Message Processor:

$>beans
...
#domain = NIO:
NIO:name=accepted,scope=0,type=selectors
NIO:name=accepted,type=total
NIO:name=asyncTasks,scope=0,type=selectors
NIO:name=asyncTasks,type=total
NIO:name=asyncTimeMS,scope=0,type=selectors
NIO:name=asyncTimeMS,type=total
NIO:name=closeFailed,scope=0,type=selectors
NIO:name=closeFailed,type=total
NIO:name=closeSuccessful,scope=0,type=selectors
NIO:name=closeSuccessful,type=total
NIO:name=connected,scope=0,type=selectors
NIO:name=connected,type=total
NIO:name=connectionAvoidedByMarkDown,scope=0,type=selectors
NIO:name=connectionAvoidedByMarkDown,type=total
NIO:name=currentAccepted,scope=0,type=selectors
NIO:name=currentAccepted,type=total
NIO:name=currentConnected,scope=0,type=selectors
NIO:name=currentConnected,type=total
NIO:name=currentConnectionsPending,scope=0,type=selectors
NIO:name=currentConnectionsPending,type=total
NIO:name=currentPoolSize,scope=0,type=selectors
NIO:name=currentPoolSize,type=total
NIO:name=currentServers,scope=0,type=selectors
NIO:name=currentServers,type=total
NIO:name=maxOpenCount,scope=0,type=selectors
NIO:name=maxOpenCount,type=total
NIO:name=maximumConnectionsOpened,scope=0,type=selectors
NIO:name=maximumConnectionsOpened,type=total
NIO:name=openCount,scope=0,type=selectors
NIO:name=openCount,type=total
NIO:name=pooledConnectionClose,scope=0,type=selectors
NIO:name=pooledConnectionClose,type=total
NIO:name=timeouts,scope=0,type=selectors
NIO:name=timeouts,type=total
...
#domain = java.lang:
java.lang:name=Code Cache,type=MemoryPool
java.lang:name=CodeCacheManager,type=MemoryManager
java.lang:name=Compressed Class Space,type=MemoryPool
java.lang:name=Copy,type=GarbageCollector
java.lang:name=Eden Space,type=MemoryPool
java.lang:name=MarkSweepCompact,type=GarbageCollector
java.lang:name=Metaspace Manager,type=MemoryManager
java.lang:name=Metaspace,type=MemoryPool
java.lang:name=Survivor Space,type=MemoryPool
java.lang:name=Tenured Gen,type=MemoryPool
java.lang:type=ClassLoading
java.lang:type=Compilation
java.lang:type=Memory
java.lang:type=OperatingSystem
java.lang:type=Runtime
java.lang:type=Threading
#domain = java.nio:
java.nio:name=direct,type=BufferPool
java.nio:name=mapped,type=BufferPool
#domain = java.util.logging:
java.util.logging:type=Logging
$>get -b NIO:name=accepted,type=total *

5. Now, try executing below command to check attributes of java.lang:type=Memory bean and their values:

$>get -b java.lang:type=Memory *

#mbean = java.lang:type=Memory:
Verbose = false;
ObjectPendingFinalizationCount = 0;
HeapMemoryUsage = {
  committed = 259653632;
  init = 268435456;
  max = 518979584;
  used = 88379536;
 };
NonHeapMemoryUsage = {
  committed = 124452864;
  init = 2555904;
  max = -1;
  used = 122300072;
 };
ObjectName = java.lang:type=Memory;

6. Similarly, use following NIO bean to check accepted thread count:

$>get -b NIO:name=accepted,type=total *

#mbean = NIO:name=accepted,type=total:
Value = 6063;

References

Version history
Last update:
‎05-30-2019 06:05 PM
Updated by: