io.github.maksymdolgykh.dropwizard:dropwizard-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.

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

io.github.maksymdolgykh.dropwizard
ArtifactId

ArtifactId

dropwizard-micrometer-core
Last Version

Last Version

2.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

io.github.maksymdolgykh.dropwizard:dropwizard-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.
Project URL

Project URL

https://github.com/MaksymDolgykh/dropwizard-micrometer
Source Code Management

Source Code Management

https://github.com/maksymdolgykh/dropwizard-micrometer

Download dropwizard-micrometer-core

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.maksymdolgykh.dropwizard/dropwizard-micrometer-core/ -->
<dependency>
    <groupId>io.github.maksymdolgykh.dropwizard</groupId>
    <artifactId>dropwizard-micrometer-core</artifactId>
    <version>2.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.maksymdolgykh.dropwizard/dropwizard-micrometer-core/
implementation 'io.github.maksymdolgykh.dropwizard:dropwizard-micrometer-core:2.0.5'
// https://jarcasting.com/artifacts/io.github.maksymdolgykh.dropwizard/dropwizard-micrometer-core/
implementation ("io.github.maksymdolgykh.dropwizard:dropwizard-micrometer-core:2.0.5")
'io.github.maksymdolgykh.dropwizard:dropwizard-micrometer-core:jar:2.0.5'
<dependency org="io.github.maksymdolgykh.dropwizard" name="dropwizard-micrometer-core" rev="2.0.5">
  <artifact name="dropwizard-micrometer-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.maksymdolgykh.dropwizard', module='dropwizard-micrometer-core', version='2.0.5')
)
libraryDependencies += "io.github.maksymdolgykh.dropwizard" % "dropwizard-micrometer-core" % "2.0.5"
[io.github.maksymdolgykh.dropwizard/dropwizard-micrometer-core "2.0.5"]

Dependencies

compile (5)

Group / Artifact Type Version
io.dropwizard : dropwizard-core jar 2.0.12
io.prometheus : simpleclient_common jar 0.7.0
io.prometheus : simpleclient_servlet jar 0.7.0
io.micrometer : micrometer-core jar 1.3.12
io.micrometer : micrometer-registry-prometheus jar 1.3.12

test (4)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.6.2
org.junit.jupiter : junit-jupiter-engine jar 5.6.2
io.dropwizard : dropwizard-testing jar 2.0.12
org.assertj : assertj-core jar 3.17.1

Project Modules

There are no modules declared in this project.

dropwizard-micrometer

Dropwizard bundle that enables your dropwizard application for exposition of micrometer-like metrics (system, jvm and http requests) as a prometheus endpoint.

Packages

  • 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.

Usage

You can find an example of usage in the ExampleApplication.

Below are the steps explained in more detail specifically for each package.

dropwizad-micrometer-core

This package provides a minimal setup, i.e. it instantiates /prometheus endpoint, adds system and JVM metrics utilizing micrometer instrumentation and optionally you can setup servlet filter to record HTTP requests latencies/statuses.

Add dependency into your pom.xml

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-core</artifactId>
            <version>2.0.5</version>
        </dependency>
        ...
        ...
    </dependencies>

Import DropwizardMicrometer classes in your Application class

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 the bundle to your application

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());
        //...
        //...
    }
    //...
    //...
}

This will expose /prometheus endpoint in admin connector, by default admin connector is exposed at port 8081 in dropwizard apps.

Assign servlet filter to the environment

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 etc
  • status, response status, i.e. 200, 404, 500 etc
  • uri, request path

dropwizad-micrometer-jdbi

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:

Add dependency into your pom.xml

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 MicrometerJdbiTimingCollector class in your Application class

import io.github.maksymdolgykh.dropwizard.micrometer.MicrometerJdbiTimingCollector;

Set TimingColletor for Jdbi object

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

License

This project is licensed under the Apache License 2.0 (LICENSE)

Versions

Version
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0