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

Histograms

A histogram is a type of metric that samples the distribution of data. It is mostly used to record the distribution of the time it takes to execute the decorated method. Histograms cannot be declared via dedicated annotation, unlike other types, but a timer, for example, includes histogram data. To use a histogram on its own, you need to register and update it in code:

// Register the Histogram@Inject@Metric(absolute = true)private Histogram aHistogram;// Update with a value from 0 to 10@GET@Path("/h")public String getHistogram() {  aHistogram.update((int) (Math.random() * 10.0));  return "Histogram called";}

This way of using metrics in code is feasible for the other types as well.

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