Convert Figma logo to code with AI

micrometer-metrics logomicrometer

An application observability facade for the most popular observability tools. Think SLF4J, but for observability.

4,436
979
4,436
252

Top Related Projects

Prometheus instrumentation library for JVM applications

7,825

:chart_with_upwards_trend: Capturing JVM- and application-level metrics. So you know what's going on.

A scalable, distributed Time Series Database.

Quick Overview

Micrometer is an application metrics facade that supports numerous monitoring systems. It provides a simple, vendor-neutral interface for collecting and reporting metrics in JVM-based applications. Micrometer allows you to instrument your code with dimensional metrics, providing a powerful way to monitor, observe, and debug your applications.

Pros

  • Vendor-neutral API, allowing easy switching between different monitoring systems
  • Extensive support for popular monitoring systems like Prometheus, Datadog, and InfluxDB
  • Minimal overhead and efficient metric collection
  • Integrates well with popular frameworks like Spring Boot

Cons

  • Learning curve for understanding dimensional metrics concepts
  • Some advanced features may require specific monitoring system support
  • Configuration can be complex for certain use cases
  • Limited support for non-JVM languages

Code Examples

  1. Creating a simple counter:
MeterRegistry registry = new SimpleMeterRegistry();
Counter counter = registry.counter("my.counter", "tag1", "value1");
counter.increment();
  1. Measuring execution time with a timer:
MeterRegistry registry = new SimpleMeterRegistry();
Timer timer = registry.timer("my.timer");

timer.record(() -> {
    // Code to be timed
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
});
  1. Creating a gauge to monitor a collection size:
List<String> list = new ArrayList<>();
MeterRegistry registry = new SimpleMeterRegistry();

Gauge.builder("list.size", list, List::size)
    .description("Size of the list")
    .register(registry);

list.add("item1");
list.add("item2");

Getting Started

To start using Micrometer in your project, add the following dependency to your Maven pom.xml:

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
    <version>1.10.5</version>
</dependency>

For Gradle, add this to your build.gradle:

implementation 'io.micrometer:micrometer-core:1.10.5'

Then, create a MeterRegistry instance and start instrumenting your code:

MeterRegistry registry = new SimpleMeterRegistry();
Counter counter = registry.counter("my.counter");
counter.increment();

For Spring Boot applications, Micrometer is automatically configured when you add the appropriate starter dependency, such as spring-boot-starter-actuator.

Competitor Comparisons

Prometheus instrumentation library for JVM applications

Pros of client_java

  • Native Prometheus support with direct integration
  • Optimized for Prometheus-specific features and data models
  • Lightweight and focused solely on Prometheus metrics

Cons of client_java

  • Limited to Prometheus ecosystem, less flexibility for other monitoring systems
  • Requires more manual configuration and setup compared to Micrometer
  • Smaller community and ecosystem compared to Micrometer

Code Comparison

Micrometer:

Counter counter = Metrics.counter("my.counter", "tag", "value");
counter.increment();

client_java:

Counter counter = Counter.build()
    .name("my_counter").help("My counter")
    .labelNames("tag").register();
counter.labels("value").inc();

Summary

Micrometer provides a more versatile and abstracted approach to metrics collection, supporting multiple monitoring systems. It offers a simpler API and broader ecosystem integration. client_java, on the other hand, is tailored specifically for Prometheus, providing optimized performance and native support for Prometheus features. The choice between the two depends on whether you need flexibility across different monitoring systems (Micrometer) or are committed to using Prometheus exclusively (client_java).

7,825

:chart_with_upwards_trend: Capturing JVM- and application-level metrics. So you know what's going on.

Pros of Metrics

  • More mature project with a longer history and established user base
  • Extensive documentation and community support
  • Tighter integration with other Dropwizard components

Cons of Metrics

  • Limited support for modern cloud-native environments and monitoring systems
  • Less flexible in terms of metric naming and tagging
  • Heavier dependency footprint compared to Micrometer

Code Comparison

Metrics:

MetricRegistry metrics = new MetricRegistry();
Counter counter = metrics.counter("requests");
counter.inc();

Micrometer:

MeterRegistry registry = new SimpleMeterRegistry();
Counter counter = registry.counter("requests");
counter.increment();

Both libraries offer similar basic functionality for creating and incrementing counters. However, Micrometer provides more flexibility in terms of metric naming and tagging, which is especially useful in cloud-native environments.

Micrometer also offers a more streamlined API for creating and managing meters, with built-in support for various monitoring systems. This makes it easier to integrate with different backends without changing application code.

Overall, while Metrics is a solid choice for traditional Java applications, Micrometer is better suited for modern, cloud-native environments and offers more flexibility in terms of metric collection and reporting.

A scalable, distributed Time Series Database.

Pros of OpenTSDB

  • Designed for large-scale, distributed time series data storage and querying
  • Supports high write throughput and efficient data compression
  • Offers built-in data visualization and graphing capabilities

Cons of OpenTSDB

  • Steeper learning curve and more complex setup compared to Micrometer
  • Less flexible for general-purpose application metrics
  • Requires additional infrastructure (HBase) for data storage

Code Comparison

OpenTSDB example (Java client):

TSDBClient client = new TSDBClient("localhost", 4242);
Metric metric = new Metric("cpu.usage", System.currentTimeMillis());
metric.addTag("host", "server1");
metric.setValue(0.75);
client.putMetric(metric);

Micrometer example:

MeterRegistry registry = new SimpleMeterRegistry();
Gauge.builder("cpu.usage", () -> getCpuUsage())
    .tag("host", "server1")
    .register(registry);

OpenTSDB focuses on time series data storage and querying, while Micrometer provides a more general-purpose metrics facade for various monitoring systems. OpenTSDB is better suited for large-scale, distributed systems with high data volumes, whereas Micrometer offers easier integration and flexibility for application-level metrics across different backends.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Micrometer Application Metrics

Build Status Apache 2.0 Maven Central Javadocs Revved up by Develocity

An application metrics facade for the most popular monitoring tools. Instrument your code with dimensional metrics with a vendor neutral interface and decide on the monitoring backend at the last minute.

More info on micrometer.io.

Micrometer artifacts work with Java 8 or later with a few exceptions such as the micrometer-java11 module and micrometer-jetty11.

Supported versions

See Micrometer's support policy.

Join the discussion

Join the Micrometer Slack to share your questions, concerns, and feature requests.

Snapshot builds

Snapshots are published to repo.spring.io for every successful build on the main branch and maintenance branches.

To use:

repositories {
    maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
    implementation 'io.micrometer:micrometer-core:latest.integration'
}

Milestone releases

Milestone releases are published to https://repo.spring.io/milestone. Include that as a maven repository in your build configuration to use milestone releases. Note that milestone releases are for testing purposes and are not intended for production use.

Documentation

The reference documentation is managed in the docs directory and published to https://micrometer.io/.

Contributing

See our Contributing Guide for information about contributing to Micrometer.


Licensed under Apache Software License 2.0

Sponsored by VMware