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?
Solved! Go to Solution.
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.
Define an MBean Interface
The interface should follow the SomethingMBean naming convention:
public interface CustomMetricsMBean {
int getApiCallCount();
void resetApiCallCount();
}
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++;
}
}
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).
Best Practices
Use clear naming like com.companyname:type=ProjectName,service=CustomMetrics.
Keep your MBean lightweight - avoid expensive operations in getters.
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.
Define an MBean Interface
The interface should follow the SomethingMBean naming convention:
public interface CustomMetricsMBean {
int getApiCallCount();
void resetApiCallCount();
}
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++;
}
}
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).
Best Practices
Use clear naming like com.companyname:type=ProjectName,service=CustomMetrics.
Keep your MBean lightweight - avoid expensive operations in getters.
Hi Matthew
you can refer this
Regards,
Shankar Angadi
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
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies