$ show micrometer-metrics/micrometer
Micrometer is a production-grade metrics instrumentation facade for JVM applications, providing a vendor-neutral API to collect and export dimensional metrics to over 20 monitoring backends including Prometheus, Datadog, Dynatrace, OTLP, InfluxDB, and Graphite. The core library defines fundamental meter types (Counter, Timer, Gauge, DistributionSummary, LongTaskTimer) and a higher-level Observation API for tracing-friendly instrumentation. Its modular architecture separates the core API (micrometer-core), common utilities (micrometer-commons), observation framework (micrometer-observation), and backend-specific registry implementations (micrometer-registry-*). Key entry points include MeterRegistry, ObservationRegistry, and annotations like @Timed, @Counted, and @Observed for declarative instrumentation. In production, applications record metrics through the Micrometer API, which aggregates data in-memory using step-based or cumulative counters and timers. The data is then periodically pushed to monitoring backends via push-based registries (e.g., Datadog, InfluxDB) or exposed for scraping (e.g., Prometheus). The library includes extensive binders for JVM internals, HTTP clients/servers (Jetty, OkHttp, Apache HttpClient), gRPC, caching (Caffeine, Guava), databases (MongoDB, JPA/Hibernate, JOOQ), messaging (JMS, Kafka), and logging frameworks. External dependencies include SLF4J for logging, HdrHistogram for percentile calculations, and various backend-specific client libraries. The codebase demonstrates high craftsmanship with comprehensive unit and integration tests, JMH benchmarks for performance-critical paths, JCStress concurrency tests, and a compatibility test kit for registry implementations. It follows clean architectural patterns: composite registries for multi-backend deployment, meter filters for runtime configuration, naming conventions for backend-specific adaptations, and a validation framework for configuration properties. While the project has some deprecated modules (e.g., Wavefront registry, Prometheus simpleclient) and minor duplication of utility classes, it remains actively maintained with frequent releases and strong community adoption.
The LLM identified 5 files worth highlighting for reuse:
An immutable, ordered collection of KeyValue pairs with validation against null keys/values and duplicate detection. Provides fluent builder methods (of, add, and) and efficient iteration. This is a self-contained utility class that can be extracted into any Java project needing a validated, immutable tag or key-value store, demonstrating clean API design and defensive programming.
A fluent validation utility for configuration properties, supporting checks for required values, duration ranges, and enum validity. Returns a Validated result that can be chained and aggregated. This pattern is reusable across any project requiring configuration validation, with clear error messages and composable validation logic.
A single-method interface (bindTo) that allows any component to register a set of meters with a MeterRegistry. This is a clean, reusable pattern for modular metric registration, enabling separation of concerns and testability. The interface is minimal and can be applied to any system that needs to expose metrics.
A thread-safe sliding window maximum tracker using AtomicLongFieldUpdater and ring buffer of buckets. It records values and provides the maximum over a configurable time window. This is a reusable component for any application needing rolling maximum calculations without external dependencies, demonstrating lock-free concurrency and efficient memory usage.
Abstract base class for step-rolling values used in push-based registries. It manages a rolling time window with atomic updates and provides a pattern for accumulating values over intervals. This is a reusable template for any time-windowed aggregation (e.g., rates, sums) and can be extracted with minimal adaptation, demonstrating clean separation of timing logic from metric semantics.