io.github.maksymdolgykh.dropwizard:dropwizard-micrometer

Dropwizard bundle that enables your dropwizard application for exposition of dimensional metrics with prometheus endpoint

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

io.github.maksymdolgykh.dropwizard
ArtifactId

ArtifactId

dropwizard-micrometer
Last Version

Last Version

2.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

io.github.maksymdolgykh.dropwizard:dropwizard-micrometer
Dropwizard bundle that enables your dropwizard application for exposition of dimensional metrics with prometheus endpoint
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

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • core
  • jdbi

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
1.0.0
0.0.1