liveBook · Manning

Micrometer

As explained in Quarkus in Action

Micrometer is a metrics instrumentation library that provides a vendor-neutral API for recording application measurements and exporting them to monitoring systems.

Micrometer collects application metrics through a common Java API and can export them to monitoring backends including Prometheus, Graphite, SignalFX, and Datadog. In Quarkus, the Micrometer extension is the recommended way to work with metrics. It supports both runtime-provided measurements and business metrics added to application code. section 10.3.1 section 10.3.4

Choose a metric type according to what you need to measure:

  • Counter: increment it to count occurrences of an event. section 10.3.2
  • Gauge: track a numeric value that can rise or fall, such as heap memory usage. section 10.3.2
  • Timer: measure operation duration and produce a histogram of the times. section 10.3.2
  • Distribution summary: record a histogram of numeric values that need not represent time. section 10.3.2

Counters and gauges have a single value. Timers and distribution summaries provide multiple values—by default, a maximum, count, and sum—and can also be configured to publish percentiles. Metrics can use tags for querying and aggregation. section 10.3.2 section 10.8

For a business counter, annotate a CDI bean method with `@Counted`: an interceptor registers and increments the counter when the method is called. Alternatively, inject `MeterRegistry` and call `meterRegistry.counter("orders").increment()` in the method. The registry looks up or creates that counter. Annotations are less verbose; the programmatic API offers more flexibility. section 10.3.4

@Counted(name = "orders", description = "Number of orders placed")
public void orderPlaced(OrderDetais details) {
    // order processing logic
}

This annotated method counts calls under the `orders` metric without an explicit increment in the method body. section 10.3.4

Expose and inspect metrics in Quarkus

In the Inventory service, run `quarkus extension add micrometer-registry-prometheus`, start the application in Dev mode, and request `/q/metrics`. Quarkus exposes built-in measurements there; `# HELP` lines describe metrics, `# TYPE` lines identify their types, and other lines carry values. Add `@Counted` to a registration method and invoke it to inspect an application-specific count. section 10.3.6

Prometheus periodically scrapes `/q/metrics` to collect and store measurements; Grafana queries Prometheus to display them in dashboards. This makes metrics useful for inspecting application behavior, collecting usage statistics, and troubleshooting performance. Quarkus 3.15 prefers Micrometer even though its alternative SmallRye Metrics extension supports only MicroProfile Metrics 4.0, rather than the 5.1 version in MicroProfile 6.1. section 10.3.5 section 10.7 section 10.3.1

How Quarkus in Action covers it

How deep it goes
Explains metric types, annotations, registry calls, and endpoint inspection, but does not detail Prometheus and Grafana configuration.
Examples
Uses a counted method, an Inventory service metrics endpoint, JVM uptime output, and a Grafana dashboard.
What it assumes
Assumes Java application methods and Quarkus setup while introducing metric types and explaining how annotations and MeterRegistry create counters.
What you can do after
Apply it via the Quarkus Micrometer extension to add counters and inspect built-in or custom metrics through Prometheus and Grafana.
How it connects
Links metrics to Quarkus, CDI, Prometheus, Grafana, tags, and cloud-native observability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.