Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Create a custom JMX MBean in AEM to expose application metrics

Avatar

Level 2

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

AEM BlogsLinkedIn


View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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

AEM BlogsLinkedIn


Avatar

Level 2

Avatar

Community Advisor

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/pla...

 

Thanks

Narendra