Introduction

The Dropwizard Metrics library is a widely used metrics instrumentation choice for JVM application. The 3.x release line of Dropwizard Metrics has been supported by Apache CXF starting from 3.1.0 and above, and the 4.x has become the default one since Apache CXF 3.4.0.

Metrics Provider

The Dropwizard Metrics integration is provided by CodahaleMetricsProvider.

Configuration

The CodahaleMetricsProvider accept additional properties which could be configured on a Bus level or factory bean level (using its setProperties mutator).

PropertyDescriptionDefault
org.apache.cxf.management.service.counter.name

The name prefix to prepend to each metric being reported

null

Integration with JAX-WS

Server

The typical way to plug Dropwizard Metrics integration on the server-side is by using WebServiceFeature mechanism, for which there is a dedicated MetricsFeature implementation. The snipped below illustrated the basic initialization sequence and set of the dependencies involved.

final Bus bus = ...; /* MetricRegistry instance is taken from Bus instance */
final MetricsProvider metricsProvider = new CodahaleMetricsProvider(bus);
 
final JAXWSServerFactoryBean factory = new JAXWSServerFactoryBean();
factory.setWsFeatures(Arrays.asList(new MetricsFeature(metricsProvider)));
...

Alternatively, the MetricsFeature could be supplied directly to JAX-WS endpoint, for example:

EndpointImpl endpoint = new EndpointImpl(bus, new HelloPortImpl(), null, null, new WebServiceFeature[]{
    new MetricsFeature(metricsProvider)
});

Client

The client integration is no different from the server and uses the same MetricsFeature feature.

final Bus bus = ...; /* MetricRegistry instance is taken from Bus instance */
final MetricsProvider metricsProvider = new CodahaleMetricsProvider(bus);

final JaxWsClientFactoryBean factory = new JaxWsClientFactoryBean();
factory.setFeatures(Arrays.asList(new MetricsFeature(new CodahaleMetricsProvider(bus))));
...

Integration with JAX-RS

Server

The typical way to plug Dropwizard Metrics integration  on the server-side is by using AbstractFeature which is implemented by MetricsFeature. The snipped below illustrated the basic initialization sequence and set of the dependencies involved.

final Bus bus = ...; /* MetricRegistry instance is taken from Bus instance */
final MetricsProvider metricsProvider = new CodahaleMetricsProvider(bus);

final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setFeatures(Arrays.asList(new MetricsFeature(metricsProvider)));
...

Client

The client integration is no different from the server and uses the same MetricsFeature feature.

final Bus bus = ...; /* MetricRegistry instance is taken from Bus instance */
final MetricsProvider metricsProvider = new CodahaleMetricsProvider(bus);

final JAXRSClientFactoryBean factory = new JAXRSClientFactoryBean();
factory.setFeatures(Arrays.asList(new MetricsFeature(new CodahaleMetricsProvider(bus))));
...