Dropwizard bundle that enables your dropwizard application for exposition of micrometer-like metrics (system, jvm and http requests) as a prometheus endpoint. In addition, if you use JDBI to manage mapping of objects to database tables, you can utilize dropwizad-micrometer-jdbi package to meter SQL request's latencies.
-
dropwizad-micrometer-core
Dropwizard bundle that implements prometheus endpoint and exposes core system metrics and JVM metrics utilizing micrometer instrumentation. Optionally, it provides servlet filter to record HTTP requests latencies and statuses within dimensional prometheus histogram. -
dropwizad-micrometer-jdbi
An additional module to record latencies of JDBI queries within dimensional prometheus histogram.
You can find an example of usage in the ExampleApplication.
Below are the steps explained in more detail specifically for each package.
This package provides a minimal setup, i.e. it instantiates /prometheus
endpoint, adds system and JVM metrics utilizing
micrometer instrumentation, and optionally you can set up servlet filter to record HTTP requests latencies/statuses.
If you use maven
, you can simply reference it in the <dependenccies>
block as below.
The latest version can be found in Releases or in the maven repository
<dependencies>
...
...
<dependency>
<groupId>io.github.maksymdolgykh.dropwizard</groupId>
<artifactId>dropwizard-micrometer-core</artifactId>
<version>2.0.5</version>
</dependency>
...
...
</dependencies>
import io.github.maksymdolgykh.dropwizard.micrometer.MicrometerBundle;
import io.github.maksymdolgykh.dropwizard.micrometer.MicrometerHttpFilter;
import javax.servlet.FilterRegistration;
import javax.servlet.DispatcherType;
import java.util.EnumSet;
Add MicrometerBundle
class to the bootstrapping phase of your Application class
public class ExampleApplication extends Application<ExampleConfiguration> {
//...
//...
@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
//...
//...
bootstrap.addBundle(new MicrometerBundle());
//...
//...
}
//...
//...
}
You will also need to make your ExampleConfiguration
class implement MicrometerBundleConfiguration
in order to provide the bundle with the configuration:
public class ExampleConfiguration extends Configuration implements MicrometerBundleConfiguration {
@JsonProperty("prometheus")
private PrometheusConfiguration prometheusConfiguration = new PrometheusConfiguration();
@Override
public PrometheusConfiguration getPrometheusConfiguration() {
return prometheusConfiguration;
}
//...
//...
}
Assuming, the above example, configuration element is prometheus
, so you can use configuration block like this in a config file:
prometheus:
endpoint: "/prometheus"
This will expose /prometheus
endpoint in admin connector, by default admin connector is exposed at port 8081
in dropwizard apps.
To leverage latency metrics per http endpoint you need to assign servlet filter to the environment
in your Application class within run
method
public class ExampleApplication extends Application<ExampleConfiguration> {
//...
//...
@Override
public void run(ExampleConfiguration configuration, Environment environment) {
//...
//...
FilterRegistration.Dynamic micrometerFilter = environment.servlets().addFilter("MicrometerHttpFilter", new MicrometerHttpFilter());
micrometerFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
}
This way all http requests will be metered and metrics will be recorded within http_server_requests_seconds
histogram
with the following labels:
method
, http method, i.e.GET
,POST
etcstatus
, response status, i.e.200
,404
,500
etcuri
, request path
If you use JDBI to manage mapping of objects to database tables, you can utilize
dropwizad-micrometer-jdbi package to meter SQL request's latencies.
It depends on dropwizad-micrometer-core
, so that to use dropwizad-micrometer-jdbi
package
the core package should be already installed and bundle should be added to your dropwizard application
(see how to install it in dropwizad-micrometer-core section).
Once dropwizad-micrometer-core
is installed, the steps to install dropwizad-micrometer-jdbi
package are:
If you use maven
, you can simply reference it in the <dependenccies>
block as below.
The latest version can be found on in the maven repository
<dependencies>
...
...
<dependency>
<groupId>io.github.maksymdolgykh.dropwizard</groupId>
<artifactId>dropwizard-micrometer-jdbi</artifactId>
<version>2.0.5</version>
</dependency>
...
...
</dependencies>
import io.github.maksymdolgykh.dropwizard.micrometer.MicrometerJdbiTimingCollector;
To use the class you just need to set TimingColletor
for Jdbi object, where it should be done depends on how your
Application is organized - it might be in the run
method of your Application
class, or you might have separate
class to configure DAO.
database.setTimingCollector(new MicrometerJdbiTimingCollector());
With this setup all jdbi requests will be metered and metrics will be recorded within jdbi_requests_seconds
histogram
This project is licensed under the Apache License 2.0 (LICENSE)