JMX and Jolokia

Reference: okminseok.blogspot.comarrow-up-right, github.com/eugenparrow-up-right

What is JMX?

  • A technology that defines a complete architecture and a set of design patterns for monitoring and managing Java Applications

  • Think of it as an API that allows you to monitor the state of a running application and change its settings

    • It enables managing applications at runtime

    • It has been included as a standard feature since JDK 1.5

      • It was originally created to provide various features for application management

JMX Terminology

  • ManagedResource

    • A resource that is the target of management

  • MBean (Managed Bean)

    • A class instantiated in the JVM through dependency injection to represent a resource

    • Provides monitoring and management capabilities for Java applications

    • Provides an interface for accessing and manipulating ManagedResources

  • MBean Server

    • A Java Class that manages MBeans

    • MBeans are registered with the MBean server, and the MBean server manages all remote managers that access resources

    • An element that acts as a mediator between MBeans, applications in the same JVM, and external systems

    • All interactions with MBeans are done through the MBean Server

  • Management Application

    • An application that manages applications built using JMX

  • Notification

    • A Java object that wraps events, alerts, and information generated by MBeans

  • Instrumentation

    • Resources managed by MBeans

Getting Started with JMX

  • To manage resources through JMX, you need to create Managed Beans called MBeans, and

    • Register the created MBeans with the MBean Server

      • The MBean Server acts as an agent that manages registered MBeans

      • The MBean server is launched internally within the implemented application

  • There are rules for implementing MBeans:

    1. You must create a pair of interface and implementation,

    2. The name of the MBean interface must end with "MBean"

  • If you only want to monitor exposed variables, you can omit the setter

ex)

  • ObjectName has a structure of domain and key

    • By convention, the domain uses the Java package name to avoid naming conflicts

    • Keys can have multiple key=value pairs separated by commas

Jolokia and JMX

  • Generally, only Java code can directly access the JMX API, but there are adaptors that convert the JMX API to standard protocols

    • One of them is Jolokia, which converts the JMX API to HTTP

  • Jolokia is an agent that can be deployed in a JVM,

    • It exposes MBeans through REST-like HTTP endpoints,

    • Making all information easily available to non-Java applications running on the same host

      • In a standard JVM, it can be deployed as an agent,

      • In Java EE, it can be deployed as a WAR, OSGI, or Module agent

Last updated