Sunday, January 30, 2011

Monitoring your Java application with JMX - Part 1

What is JMX?
Java Management Extension technology which comes with the Java platform provides a simple and standard way of managing applications and services.You can use JMX technology to monitor the JVM also. It (JVM) has built-in instrumentation which enables you to monitor and manage it.

What we have to do?
To be able to monitor via JMX, you have to set certain system properties when you start the JVM (i.e. When you start your Java application). Following is the syntax of setting a system property.
java -Dpropertyname=value
You can provide these system properties at the commandline or in a configuration file also. Based on your requirement on monitoring, these system properties change. I will explain the necessary properties when the article progresses.

Local and remote monitoring
You can monitor your application/jvm locally or remotely. For remote monitoring to be possible you have to set the follwing properties. (if we do not provide a value, default value will be taken. i.e 'true' for htis property). where portNum is the port which you want to enable the JMX connection.

Monitoring your java application using JConsole
JConsole is a graphical monitoring tool to monitor jvm/java applications. Executable file for JConsole is located in the JDK_HOME/bin folder. If you have this folder in your system path, you can simply start it by typing jconsole. Else, you will have to provide the absolute path for it. There are two ways to monitor a local application.

1.You can provide the process id of the application when you start JConsole
jconsole processID

2.If you dont provide a process ID, JConsole will list the available local applications for monitoring and you can select from the list.

It is necessary that both JConsole and the Java application started by the same user because JMX uses operating system's file permissions. Local monitoring is not recommended for production environments. The reason for this is, JConsole consumes a considerable amount of resources when running.

For remote monitoring, you either need the jmx service url or the host:port combination. You can provide the host:port combination at JConsole start time or later.
jconsole host:port

Lets monitor tcpmon, which is a java application using JConsole locally. First, start tcpmon by running in TCPMON_HOME/build folder. Then start a JConsole. You will see the available applications to be monitored as shown in the image below.

Select tcpmon from the list and click connect. Then you will be connected monitor tcpmon as shown below.

In my next article (i.e. Part 2), I will explain remote monitoring related requirements such as authentication, ssl. There will be an example explaining how to monitor your application remotely.


  1. For JEE servers, there are also some online monitoring tools which leverage JMX (e.g. JBison uses JBoss's jmx-console to read memory usage etc). It's a quick and low-cost way to get some useful monitoring for your app.


  2. Even for web based applications, we can configure monitoring using various open source tools, which are described here.

  3. @Adam: Thanks for the info.
    @panbhatt: yes, I'll include it in another article. Thanks for the link.

  4. ISO Certification Consultancy in singapore,iso 9001:2015,9001 qms training,qms consulting,iso 14001:2015,14001 training,45001:2016,45001 training,27001 training, iso 9001,iso 14001,iso 45001,iso 29990,ohsas 18001,resident engineer,re resident technical officer,rto,part-time rto,stu-structural,stu-safety,pdu,cet,sdu,concrete quality,eurocode,precast,diaphragm wall,non-destructive testing of concrete. Rstar

  5. iso certification,iso certification singapore,iso certification bodies,iso training,iso management in singapore,iso training in singapore,iso management in singapore,iso consultancy,iso 9001 certification in singapore,iso 9000 certification in singapore,iso 18001 certification in singapore,bs ohsas 18001 certification in singapore,iso consultancy in singapore,iso quality management in singapore,iso certification bodies,iso certification company in singapore,certification body singapore,iso 14001 singapore,iso consultants,iso singapore Qscert

  6. Thanks for sharing the information maintain the applications.
    ISO certification providers in india