

Integrating dropwizard metrics with prometheus metrics
source link: https://blog.adamgamboa.dev/dropwizard-with-prometheus-metrics/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Integrating dropwizard metrics with prometheus metrics
Dropwizard is a framework in Java to create web application and focus on micro-services providing a lot nice features. One of those are metrics, Dropwizard metrics helps to instrument exposing metrics with JVM data (memory, cpu, threads), API metrics (requests, execution time, errors, etc) and even custom metrics.
However, Dropwizard metrics lacks on features like labels and use to make calculations on the client side, for example: a metric use to have a 15 minutes lifecycle, so it metrics like Gauges, or Timer provide an average value on the last minute, five minutes and 15 minutes. Which is useful in some case, but also not accurate in other scenarios.
Prometheus metrics is an extended format to handle metrics, several tools are able to process them (Prometheus Server, Graphana, Kibana, etc). The prometheus client library allow the code to create 4 types of metrics: Counter, Gauges, Histogram and Summary. So, we can create our custom metrics, depending on the needs.
It could be the case, it is needed to use Prometheus metrics, because of the format and the custom metrics and its features (for example: labels), but at the same time it’s required to expose all those metrics already provided by Dropwizard. The good news is that integrating the two instrumentation metrics libraries requires only a few of lines of code.
Adding dependency
<dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_dropwizard</artifactId> <version>0.16.0</version> </dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_dropwizard</artifactId>
<version>0.16.0</version>
</dependency>
Integrating dropwizard metrics with prometheus metrics
import io.prometheus.client.CollectorRegistry; import io.prometheus.client.dropwizard.DropwizardExports; @Override public void run(Configuration configuration, Environment environment){ ... CollectorRegistry.defaultRegistry.register(new DropwizardExports(environment.metrics())); ... }
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
@Override
public void run(Configuration configuration, Environment environment){
...
CollectorRegistry.defaultRegistry.register(new DropwizardExports(environment.metrics()));
...
}
Conclusion
With that few changes, all the metrics exposed by Dropwizard Metrics (using annotations in endpoints, or JVM metrics, or custom metrics) are also collected by Prometheus, and they will be exposed in prometheus format together with your prometheus metrics.
Reference
Recommend
-
144
In a previous post, I've described how we can monitor our spring boot application(s) metrics over time, in a time-series fashion, using the elastic stack. In this post we'll discuss how to achieve the same goal, using another open source stack:...
-
75
Go Prometheus client metrics explained.
-
47
To facilitate the growth of Uber’s global operations, we need to be able to quickly store and access billions of metrics on our back-end systems at any given time. As part of our robust and scalable metrics infrastructur...
-
39
What is Dropwizard? Dropwizard is an open source Java framework used for the fast development of RESTful web services. Or better, it's a light-weight best-in-class set of tools and frameworks for building RESTful web services. It's pretty easy t...
-
73
README.md Dropwizard
-
8
Publishing Dropwizard Metrics to Kafka Mar 3, 2017 | metrics This post is about combining Dropwiz...
-
6
Metrics Capturing JVM- and application-level metrics. So you know what's going on. For more information...
-
2
Dropwizard is a REST-oriented framework that draws together several Java packages into a cohesive whole. It is an alternative to Spring (and Spring’s WebMVC package). Dropwizard delivers a more streamlined experience. It adopts even more conf...
-
3
Release Highlights Dropwizard 2.1.0 comes with the latest and greatest from the Dropwizard team and countless contributors from the community....
-
4
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK