Create a custom JMX MBean in AEM to expose application metrics | Community
Skip to main content
Level 2
July 25, 2025
Solved

Create a custom JMX MBean in AEM to expose application metrics

  • July 25, 2025
  • 3 replies
  • 435 views

Hi Community,

We want to expose some custom application metrics like cache hit ratio, external API call counts, or custom service health checks through JMX Console for better monitoring.

I am aware that AEM exposes several built-in MBeans (via /system/console/jmx), but we need custom MBeans for our project.

What is the recommended approach for creating custom JMX MBeans?

Best answer by SantoshSai

Hi @matthewda19,

You can register custom JMX MBeans via OSGi services, enabling you to expose application-specific metrics (eg. API call counts, cache hit/miss ratios) through the /system/console/jmx console.

  1. Define an MBean Interface
    The interface should follow the SomethingMBean naming convention:

    public interface CustomMetricsMBean { int getApiCallCount(); void resetApiCallCount(); }
  2. Implement the MBean
    Implement the interface in a class and annotate it as an OSGi component:

    import org.osgi.service.component.annotations.Component; import org.apache.felix.scr.annotations.Service; @Component(service = CustomMetricsMBean.class, immediate = true) public class CustomMetrics implements CustomMetricsMBean { private int apiCallCount = 0; @Override public int getApiCallCount() { return apiCallCount; } @Override public void resetApiCallCount() { apiCallCount = 0; } // Increment this from your service logic public void incrementApiCallCount() { apiCallCount++; } }
  3. Access the JMX Console
    Once deployed, navigate to:
    http://localhost:4502/system/console/jmx
    Search for your MBean by its name (eg. org.example: type=CustomMetrics).

  4. Best Practices

    • Use clear naming like com.companyname:type=ProjectName,service=CustomMetrics.

    • Keep your MBean lightweight - avoid expensive operations in getters.

3 replies

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
July 25, 2025

Hi @matthewda19,

You can register custom JMX MBeans via OSGi services, enabling you to expose application-specific metrics (eg. API call counts, cache hit/miss ratios) through the /system/console/jmx console.

  1. Define an MBean Interface
    The interface should follow the SomethingMBean naming convention:

    public interface CustomMetricsMBean { int getApiCallCount(); void resetApiCallCount(); }
  2. Implement the MBean
    Implement the interface in a class and annotate it as an OSGi component:

    import org.osgi.service.component.annotations.Component; import org.apache.felix.scr.annotations.Service; @Component(service = CustomMetricsMBean.class, immediate = true) public class CustomMetrics implements CustomMetricsMBean { private int apiCallCount = 0; @Override public int getApiCallCount() { return apiCallCount; } @Override public void resetApiCallCount() { apiCallCount = 0; } // Increment this from your service logic public void incrementApiCallCount() { apiCallCount++; } }
  3. Access the JMX Console
    Once deployed, navigate to:
    http://localhost:4502/system/console/jmx
    Search for your MBean by its name (eg. org.example: type=CustomMetrics).

  4. Best Practices

    • Use clear naming like com.companyname:type=ProjectName,service=CustomMetrics.

    • Keep your MBean lightweight - avoid expensive operations in getters.

Santosh Sai
Level 2
July 25, 2025
narendragandhi
Community Advisor
Community Advisor
July 25, 2025

Hi @matthewda19 

 

You could take a look at the MBean created in ACS Commons for HTTP cache - https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/subpages/jmx.html

 

and also the Adobe documentation for details and example MBean - https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/developing/platform/jmx-integration

 

Thanks

Narendra