Get CXF Performance Monitoring in JMX
CXF provides in its “cxf-rt-management” module a performance extension which registers through JMX to expose services metrics.
This is usable in TomEE and setup is actually 1 line of code.
Let's see how to benefit from this feature particularly useful during development phases.
CXF and TomEE dependencies
If you use Maven (or a maven repository friendly build tool like Gradle/Ivy) the artifacts to add are:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-management</artifactId>
<version>3.1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-cxf-transport</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
NOTE: don't forget to use scope provided since we need to reuse TomEE provided ones.
Register the CounterRepository
CXF provides this feature through “CounterRepository” class. All you need to do is to call:
new org.apache.cxf.management.counters.CounterRepository().setBus(bus);
But how to get the bus? That's where the “openejb-cxf-transport” helps us, as TomEE provides a static utility to access the bus used by the server:
final Bus bus = CxfUtil.getBus();
Finally, we will use CDI (or you can use EJB as well) to register the repository at startup:
import org.apache.cxf.Bus;
import org.apache.cxf.management.counters.CounterRepository;
import org.apache.cxf.management.interceptor.ResponseTimeMessageInInterceptor;
import org.apache.openejb.server.cxf.transport.util.CxfUtil;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class CxfStatSetup {
void setup(@Observes @Initialized(ApplicationScoped.class) final Object init) {
final Bus bus = CxfUtil.getBus();
if (bus.getInInterceptors().stream()
.filter(ResponseTimeMessageInInterceptor.class::isInstance)
.findAny().isPresent()) {
return;
}
new CounterRepository().setBus(bus);
}
}
NOTE: strictly speaking, we don't need the “if” block. However, this allows us to not re-register the repository multiple times, in case you put this code in multiple webapps.
CXF Statistics in JMX
Then you can connect to your JVM once your application is deployed, and check cxf MBeans. You will probably not see anything until you do your first request. But then, you will see your endpoint with some statistics as you can see on the following capture:
One interesting thing is that you can enable/disable monitoring and check response times and errors.
Of course this is not a full blown solution or even a real monitoring solution like Sirona but it allows to have some overview of your services quite immediately and without a big investment in terms of time, setup or infrastructure.
Note: this feature has been added in TomEE directly thanks to TOMEE-1826 and is expected for version 7.0.1.
From the same author:
In the same category:

