metrics
:chart_with_upwards_trend: Capturing JVM- and application-level metrics. So you know what's going on.
Top Related Projects
An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
Prometheus instrumentation library for JVM applications
A scalable, distributed Time Series Database.
Quick Overview
Dropwizard Metrics is a Java library that provides a powerful toolkit for measuring the behavior of critical components in production environments. It offers a wide range of metrics types and reporting options, allowing developers to gain insights into application performance, resource utilization, and overall health.
Pros
- Comprehensive set of metric types (gauges, counters, histograms, timers, etc.)
- Flexible reporting options (JMX, console, CSV, SLF4J, Graphite, etc.)
- Easy integration with various Java frameworks and libraries
- Minimal overhead and high performance
Cons
- Learning curve for effectively using all features
- Can lead to metric sprawl if not managed carefully
- Limited built-in visualization options (relies on external tools)
- Some advanced features require additional dependencies
Code Examples
- Creating and using a Timer:
private final Timer responsesTimer = metrics.timer(name(RequestHandler.class, "responses"));
public Response handleRequest(Request request) {
try (Timer.Context context = responsesTimer.time()) {
// Handle the request
return processRequest(request);
}
}
- Using a Counter:
private final Counter pendingJobs = metrics.counter(name(JobQueue.class, "pending-jobs"));
public void addJob(Job job) {
pendingJobs.inc();
queue.offer(job);
}
public Job takeJob() {
Job job = queue.poll();
if (job != null) {
pendingJobs.dec();
}
return job;
}
- Registering a Gauge:
metrics.register(name(Cache.class, "size"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return cache.size();
}
});
Getting Started
To start using Dropwizard Metrics in your Java project:
- Add the dependency to your
pom.xml
(for Maven):
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.2.9</version>
</dependency>
- Create a
MetricRegistry
instance:
final MetricRegistry metrics = new MetricRegistry();
- Use the registry to create and manage metrics in your code:
Counter evictions = metrics.counter(name(Cache.class, "evictions"));
evictions.inc();
Timer responses = metrics.timer(name(Http.class, "responses"));
Timer.Context context = responses.time();
try {
// Perform the operation being timed
} finally {
context.stop();
}
- Set up a reporter to output the metrics (e.g., to console):
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(1, TimeUnit.MINUTES);
Competitor Comparisons
An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
Pros of Micrometer
- Vendor-neutral metrics collection facade, supporting multiple monitoring systems
- Dimensional metrics with tags, allowing for more flexible and powerful data analysis
- Spring Boot integration out-of-the-box
Cons of Micrometer
- Steeper learning curve due to more complex API
- Potentially higher memory footprint for applications with many metrics
Code Comparison
Metrics:
final Counter requests = metrics.counter("requests");
requests.inc();
Micrometer:
Counter requests = Counter.builder("requests")
.tag("status", "success")
.register(registry);
requests.increment();
Key Differences
- Micrometer focuses on dimensional metrics, while Metrics uses a hierarchical naming structure
- Micrometer supports a wider range of monitoring systems out-of-the-box
- Metrics is more lightweight and simpler to use for basic use cases
Use Cases
- Metrics: Ideal for simple applications or those already using Dropwizard
- Micrometer: Better suited for complex systems, microservices, or when targeting multiple monitoring backends
Community and Ecosystem
- Metrics: Mature project with a stable API and extensive documentation
- Micrometer: Growing rapidly, with strong support from the Spring community and monitoring vendors
Prometheus instrumentation library for JVM applications
Pros of client_java
- Built-in support for Prometheus' pull-based model and data format
- Offers more advanced features like histograms and summaries
- Better integration with Prometheus ecosystem and tools
Cons of client_java
- Steeper learning curve for developers not familiar with Prometheus
- Less flexibility in metric types compared to Metrics
Code Comparison
Metrics:
final MetricRegistry metrics = new MetricRegistry();
final Counter requests = metrics.counter("requests");
requests.inc();
client_java:
static final Counter requests = Counter.build()
.name("requests_total").help("Total requests.").register();
requests.inc();
Key Differences
- Metrics is more general-purpose and can be used with various backends
- client_java is specifically designed for Prometheus integration
- Metrics offers a wider range of metric types out-of-the-box
- client_java provides better support for Prometheus-specific features like labels
Use Cases
- Choose Metrics for a versatile metrics library with multiple backend options
- Opt for client_java when working primarily with Prometheus and its ecosystem
Community and Ecosystem
- Metrics has a larger community and more third-party integrations
- client_java is tightly integrated with the Prometheus ecosystem
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 aggregation and downsampling capabilities
Cons of OpenTSDB
- More complex setup and configuration compared to Metrics
- Requires additional infrastructure (HBase, Hadoop) for deployment
- Steeper learning curve for implementation and management
Code Comparison
OpenTSDB example:
TSDBClient client = new TSDBClient("localhost", 4242);
Metric metric = new Metric("cpu.usage", System.currentTimeMillis());
metric.addTag("host", "server1");
metric.setValue(75.5);
client.addMetric(metric);
Metrics example:
MetricRegistry registry = new MetricRegistry();
Counter requests = registry.counter("requests");
requests.inc();
Meter requestMeter = registry.meter("requests");
requestMeter.mark();
OpenTSDB focuses on distributed time series data storage and querying, while Metrics provides a simpler, in-memory metrics collection and reporting system. OpenTSDB is better suited for large-scale, long-term data storage and analysis, whereas Metrics is more appropriate for application-level monitoring and reporting. The choice between the two depends on the specific requirements of the project, such as scale, data retention needs, and complexity tolerance.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Metrics
ð Capturing JVM- and application-level metrics. So you know what's going on.
For more information, please see the documentation
Versions
Version | Source Branch | Documentation | Status |
---|---|---|---|
<2.2.x | - | - | ð´ unmaintained |
2.2.x | - | Docs | ð´ unmaintained |
3.0.x | release/3.0.x branch | Docs | ð´ unmaintained |
3.1.x | release/3.1.x branch | Docs | ð´ unmaintained |
3.2.x | release/3.2.x branch | Docs | ð´ unmaintained |
4.0.x | release/4.0.x branch | Docs | ð´ unmaintained |
4.1.x | release/4.1.x branch | Docs | ð´ unmaintained |
4.2.x | release/4.2.x branch | Docs | ð¢ maintained |
5.0.x | release/5.0.x branch | - | ð¡ on pause |
Future development
New not-backward compatible features (for example, support for tags) will be implemented in a 5.x.x release. The release will have new Maven coordinates, a new package name and a backwards-incompatible API.
Source code for 5.x.x resides in the release/5.0.x branch.
License
Copyright (c) 2010-2013 Coda Hale, Yammer.com, 2014-2021 Dropwizard Team
Published under Apache Software License 2.0, see LICENSE
Top Related Projects
An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
Prometheus instrumentation library for JVM applications
A scalable, distributed Time Series Database.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot