MicroProfile Metrics
Our service has been configured, we can reason about its health, and we have resilience in place. The next thing we want to do is know how it performs. How many requests are handled, what is the longest execution time, and what is the average execution time? Questions like these can be asked, and answered, by MicroProfile Metrics.
Metrics is a vast area. In this section, we will only discuss the annotations that can be used. But know that you can define your own metrics programmatically.
Metrics offers a REST API that is, by specification, required to respond with metrics in Prometheus format. Optionally, implementations are allowed to respond in OpenMetrics format.
Metrics come in three scopes:
- Base: Spec-described metrics that vendors may supply
- Vendor: Vendor-specific metrics
- Application: Application-specific metrics
The four metric annotations are as follows:
@
Counted
@
Gauge
@
Metrics
@
Timed