This version is still in development and is not considered stable yet. For the latest stable version, please use Micrometer 1.17.1!

Registry

Meters in Micrometer are created from and held in a MeterRegistry. Each supported monitoring system has an implementation of MeterRegistry. How a registry is created varies for each implementation.

Micrometer includes a SimpleMeterRegistry that holds the latest value of each meter in memory and does not export the data anywhere. If you do not yet have a preferred monitoring system, you can get started playing with metrics by using the simple registry:

MeterRegistry registry = new SimpleMeterRegistry();
A SimpleMeterRegistry is autowired for you in Spring-based applications.

Composite Registries

Micrometer provides a CompositeMeterRegistry to which you can add multiple registries, letting you publish metrics to more than one monitoring system simultaneously:

CompositeMeterRegistry composite = new CompositeMeterRegistry();

SimpleMeterRegistry simple = new SimpleMeterRegistry();
composite.add(simple); (1)

Counter compositeCounter = composite.counter("counter"); (2)
compositeCounter.increment(); (3)
1 You can add multiple registries to a composite.
2 A counter named counter is registered to the simple registry.
3 The simple registry counter is incremented, along with counters for any other registries in the composite.
Meters should be registered after registry configuration is completed (after all registries and filters have been added). Recordings have no effect until there is a non-composite registry in the composite. Also, if a MeterRegistry is added to the CompositeMeterRegistry that already has registered meters, meter recordings that occurred before the registry was added will not be reflected in the newly added registry.

Global Registry

Micrometer provides a static global registry called Metrics.globalRegistry and a set of static builders for generating meters based on this registry (note that globalRegistry is a composite registry):

class MyComponent {
    Counter featureCounter = Metrics.counter("feature", "region", "test"); (1)

    void feature() {
        featureCounter.increment();
    }

    void feature2(String type) {
        Metrics.counter("feature.2", "type", type).increment(); (2)
    }
}

class MyApplication {
    void start() {
        // wire your monitoring system to global static state
        Metrics.addRegistry(new SimpleMeterRegistry()); (3)
    }
}
1 Wherever possible (and especially where instrumentation performance is critical), store Meter instances in fields to avoid a lookup on their name or tags on each use.
2 When tags need to be determined from local context, you have no choice but to construct or lookup the Meter inside your method body. The lookup cost is just a single hash lookup, so it is acceptable for most use cases.
3 It is OK to add registries after meters have been created with code like Metrics.counter(…​). These meters are added to each registry, as it is bound to the global composite.