To ensure reliable operation of software it is necessary to monitor essential system parameters. There is already JMX as standard to expose metrics, but remote-JMX is not easy to deal with and especially does not fit well in a polyglot environment where other services are not running on the JVM. To enable monitoring in an easy fashion, the MicroProfile Metrics specification provides a standard to instrument an application with metrics and provides a simple REST endpoint for integration with monitoring services.
MicroProfile Metrics provides 4 different metric types that can be used to instrument an application. Developers can
create an accompanying Metadata object to supply the metric's name,
description and units. Once the metric and the metadata are registered against the application
MetricRegistry, the metrics will be available in the REST
endpoints.
Counter is used to measure an increasing value.
Example usage:
Counter count = metricRegistry.counter(metadata);
count.inc();
Gauge is used to provide the immediate measurement of a value.
Example usage:
Gauge<Double> temperature = new Gauge<Double>() {
public Double getValue() {
return getTemperature();
}
};
metricRegistry.register(metadata, temperature);
Histogram is used to sample and compute the distribution of values
Example usage:
Histogram histogram = metricRegistry.histogram(metadata);
histogram.update(score);
Timer is used to measure the duration of an event as well as the
frequency of occurrence.
Example usage:
Timer timer = metricRegistry.timer(metadata);
try (Timer.Context context = timer.time()) {
... // code that will be timed
}
| Modifier and Type | Interface and Description |
|---|---|
| public interface | Counter
An incrementing counter metric. |
| public interface | Counting
An interface for metric types which have counts. |
| public interface | |
| public interface | Histogram
A metric which calculates the distribution of a value. |
| public interface | Metadata
Bean holding the metadata of one single metric. |
| public interface | Metric
A tag interface to indicate that a class is a metric. |
| public interface | MetricFilter
A filter used to determine whether or not a metric should be reported, among other things. |
| public interface | MetricRegistry
The registry that stores metrics and their metadata. |
| public interface | Sampling
An object which samples values. |
| public interface | Timer
A timer metric which aggregates timing durations and provides duration statistics |
| Modifier and Type | Class and Description |
|---|---|
| public class | DefaultMetadata
The default implementation of |
| public class | MetadataBuilder
The |
| public class | MetricID
A unique identifier for
|
| public class | MetricUnits
Standard units constants for metric's |
| public abstract class | |
| public class | Tag
Tag represents a singular metric tag key and value pair. |