O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Supplying application-specific metrics

Applications can choose to expose metric data via a CDI programming model. This model was inspired by DropWizard Metrics, so that it is easier to transition applications to MP-Metrics. It also uses the annotations from DropWizard Metrics, which have been augmented to support metadata.

Let’s start with an example by defining a counter that is then incremented in code:

@Inject@Metric(absolute = true, description = "# calls to /health")Counter hCount; // This is the counter@GET@Path("/health")public Response getHealth() throws Exception {    hCount.inc(); // It is increased in the application    [...]}

In this example, we are registering a counter by getting it injected into the hCount variable:

The @Metric

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required