The Java 2 Platform, Standard Edition beginning with version 5.0, supports JMX 1.2 and JMX Remote API 1.0, which is now the official JMX reference implementation. It includes significant monitoring and management features which can be divided into three broad categories.
Instrumentation for the Java Virtual Machine (Java VM) that enables built-in (or out-of-the-box) management capabilities that can be accessed both remotely and locally.
Monitoring and Management application programming interfaces (API) that provide the interface for monitoring and managing the Java VM.
Monitoring and Management tools that provide a graphical monitoring tool called JConsole, which implements the JMX API and enables you to monitor the performance of the Java VM and any instrumented applications.
The Java Management Extensions (JMX) technology is native to the Java programming language and, as a result, it offers natural, efficient, and lightweight management and monitoring extensions to Java-based functions. It can be used to monitor and manage the Java Virtual Machine and also user Java applications. The key components are the MBeans, the notification model, namely Java objects that represent resources to be managed. An MBean has a management interface consisting of the following:
- Named and typed attributes that can be read and written
- Named and typed operations that can be invoked
- Typed notifications that can be emitted by the MBean
MBeans are not accessed directly by an application but reside in a repository called an MBean server. To be useful, an MBean must be registered in an MBean server. The Java SE platform includes a built-in platform MBean server. The MBean represents a resource running in the Java virtual machine, such as an application or a Java EE technical service (transactional monitor, JDBC driver, etc.) and, of course, can be used to be monitor the health state of JVM and Java applications.
Generally, any JVM supplies the following JMX MBean Platforms that collect important information about JVM and application health status.
[table id=1 /]
In addition, almost any software vendor providing a more-or-less serious application will insert includes Mbeans to provide important information about the application state. For instance, Jboss, GlassFish, Tomcat and others use JMX MBeans to for managing and monitoring by implementing hundreds of custom Mbeans.
The Monitis JMX Monitor
The Monitis JMX Monitor represents the Java implementation of a standalone JMX client which allows it to get Mbeans attribute values from any Java application and to send them to Monitis via the Monitis open API.
This project uses the Java Management Extensions and the Monitis custom monitor approach to provide a simple solution for users who want to monitor any Java application.
If you want to monitor the JVM health state, you don’t need to make any changes in your application at all.
The only requirement for the monitored application is the following:
- The JMX agent should be enabled on the monitored application JVM and should be implemented on J2SE version 5 or higher.
- The monitored application should be started by using the following parameters:
- Normally, the JMX server doesn’t have a default port. You can choose any free port. The first available port will be set when 0 value is specified as port.
- In the password file, each username and password pair should be placed in one line with space between them.
- After you have enabled the JMX agent for remote or local use, you can monitor your application using the presented JMXMonitor.
The JMX Monitor project structure
The JMX Monitor project contains the following sources:
Please notice that we are using the cropped Open API Java client library (wrapper) – m_api.jar (which contains only the essential functionality required for the custom monitor)
The monitor.config file is used to configure JMXMonitor. It should be prepared in JSON form and has the following structure.
- The JMXMonitor tries to establish a local connection with the JMX server of the monitored application by using the application start command (if specified) or by using the defined host and port number for local/remote connections. So, you can specify one or the other. If you are defining both of these parameters, then the JMXMonitor first tries to establish a connection by using the application start command and if it fails it uses a port and host.
- You can obtain the list of existing MBeans and their attributes by using standard JMX tools – JConsole (supplied with J2SE) or any other JMX browser.
- You can add as many objects for monitoring as you desire into the configuration file. The only limitation may be insufficient space to correctly show your data on the Monitis dashboard screen.
- If some of specified MBeans aren’t accessible for some reason, then the corresponding data will be omitted and will not be sent to Monitis.
Testing and results
To check that the monitor is working correctly, the embedded test application can be started with the following parameters:
Note: you can use the “jmxserver.sh” script on a Linux machine that already contains the parameters mentioned above.
Next, you should start the JMX monitor. After some time, sufficient data will be accumulated and the results will be viewable on the user’s Monitis dashboard.
To do this, the user should log in to their Monitis account and add a new custom monitor into the dashboard.
Also, the Graphical representation of the monitored data can be shown by switching to the corresponding view:
Please look also into existing code of Monitis JMXMonitor for more details