Overview of Micrometer Application Metrics
mainmicrometer-java11 and micrometer-jetty11).repository·main·Indexed 26 days ago
https://github.com/micrometer-metrics/micrometerA dimensional metrics facade for JVM-based applications that provides a vendor-neutral API to instrument code for various monitoring backends. It includes support for Counters, Gauges, DistributionSummaries, and an Observation API for unified metrics and tracing. Compatible with Java 8 or later.
micrometer-java11 and micrometer-jetty11).Micrometer is a metrics instrumentation library for JVM-based applications. It acts as a facade over various monitoring system clients, allowing you to instrument application code without vendor lock-in. It is designed for low overhead and high portability.
Key features include:
Micrometer is a vendor-neutral observability facade for JVM-based applications, similar to how SLF4J works for logging. It allows you to instrument your application code using a consistent API while decoupling your code from specific observability backends.
Key features include:
Timer, Gauge, Counter, DistributionSummary, and LongTaskTimer using a dimensional data model for efficient drilling down into metrics.Micrometer Observation is used to instrument a wide variety of external projects, allowing developers to "instrument once and have multiple benefits out of it." Many popular libraries and frameworks already provide built-in support for Micrometer Observation.
Commonly instrumented projects include:
If your project uses one of these technologies, check the official Micrometer documentation or the specific project's integration guide to see how to enable observation.
Micrometer Observation is a mechanism for instrumenting code with metadata that can be used for metrics, tracing, and logging. An Observation lifecycle is managed by ObservationHandler objects registered in an ObservationRegistry.
Handlers react to the following events:
start: Triggered by Observation#start().stop: Triggered by Observation#stop().error: Triggered by Observation#error(exception).event: Triggered by Observation#event(event).scope started: Triggered by Observation#openScope().scope stopped: Triggered by Observation.Scope#close().ObservationRegistry: The central registry containing configuration like handlers, predicates, and filters.ObservationHandler: Reacts to lifecycle events (e.g., creating a timer when an observation starts).ObservationFilter: Mutates the Observation.Context before the observation stops (e.g., adding high-cardinality tags).ObservationPredicate: Determines if an observation should be created at all.Observation.Context: A mutable map attached to an observation used to pass state between handlers.ObservationConvention: Separates lifecycle logic from metadata configuration (naming and tags).The HighCardinalityTagsDetector monitors your MeterRegistry to identify Meters that likely have high cardinality tags. It works by counting how many Meters share the same name; if this count exceeds a configurable threshold, it triggers a notification (via logging or a custom consumer).
Note: The detector specifically identifies potential high cardinality tags by counting Meters with the same name. It does not detect random values appended to Meter names or other memory leaks.
Micrometer supports both Dimensional and Hierarchical monitoring systems.
When using a hierarchical system, Micrometer automatically flattens the tag key/value pairs and appends them to the metric name to ensure compatibility.
A Meter is the primary interface for collecting measurements (metrics) about an application.
Micrometer provides several meter types, each producing different numbers of time series metrics:
Timer: Measures both the count of timed events and the total time of all timed events.CounterGaugeDistributionSummaryLongTaskTimerFunctionCounterFunctionTimerTimeGaugeEach meter is uniquely identified by its name and its dimensions (also referred to as tags).
Micrometer handles rate aggregation differently depending on whether the target monitoring system performs math on the server or expects pre-aggregated data from the client.
Monitoring systems like Prometheus expect absolute values (e.g., the total count of increments since application start) to be reported at each publishing interval. The monitoring system then performs the rate math (e.g., rate() in PromQL) during the query.
Best Practice: For production automation, alerting, or canary analysis, always base your logic on rate-aggregated data rather than raw absolute counter values to avoid issues with service restarts or deployment dips.
Some monitoring systems either require pre-aggregated data or lack the mathematical capabilities to calculate rates from absolute values. In these cases, Micrometer performs the aggregation locally before publishing.
Micrometer uses a "step value" mechanism to maintain this data. It accumulates data for the current interval and, once the interval elapses, moves the data to a previous state. This previous state is what is reported to the backend until the next interval is completed. The value reported is always rate per second * interval.
Micrometer Observation follows a specific lifecycle. An Observation is created via an ObservationRegistry using a mutable Observation.Context.
Detailed Flow:
ObservationRegistry creates an Observation with an Observation.Context. An ObservationConvention is used to customize the name and key-value pairs.ObservationPredicate determines if the observation should be fully created or a no-op version.start()), the corresponding ObservationHandler methods (e.g., onStart) are called with the Observation.Context.stop(), a list of ObservationFilter instances is called to optionally modify the Observation.Context before the ObservationHandler.onStop methods are executed.Micrometer provides a hierarchical mapping to JMX (Java Management Extensions). This implementation is primarily used as a portable way to view metrics locally.
Note: This module is strictly used to export data to JMX. If you need to scrape data from JMX beans to report them as Micrometer metrics, this registry implementation is not required.
micrometer-registry-ganglia module provides a MeterRegistry implementation for exporting Micrometer metrics to a Ganglia metrics backend. It relies on the gmetric4j library for communication with Ganglia.