{"id":22627110,"url":"https://github.com/maksymdolgykh/dropwizard-micrometer","last_synced_at":"2025-04-11T18:51:17.992Z","repository":{"id":57734046,"uuid":"292902269","full_name":"MaksymDolgykh/dropwizard-micrometer","owner":"MaksymDolgykh","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-16T08:32:38.000Z","size":48,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T14:44:41.930Z","etag":null,"topics":["dropwizard","dropwizard-bundle","dropwizard-micrometer","dropwizard-prometheus","java","metrics","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaksymDolgykh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-04T16:59:23.000Z","updated_at":"2023-04-26T14:57:24.000Z","dependencies_parsed_at":"2023-01-29T11:32:40.834Z","dependency_job_id":null,"html_url":"https://github.com/MaksymDolgykh/dropwizard-micrometer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksymDolgykh%2Fdropwizard-micrometer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksymDolgykh%2Fdropwizard-micrometer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksymDolgykh%2Fdropwizard-micrometer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksymDolgykh%2Fdropwizard-micrometer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaksymDolgykh","download_url":"https://codeload.github.com/MaksymDolgykh/dropwizard-micrometer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248464199,"owners_count":21108238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dropwizard","dropwizard-bundle","dropwizard-micrometer","dropwizard-prometheus","java","metrics","prometheus"],"created_at":"2024-12-09T01:07:29.221Z","updated_at":"2025-04-11T18:51:17.927Z","avatar_url":"https://github.com/MaksymDolgykh.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dropwizard-micrometer\n\n[Dropwizard][dropwizard] bundle that enables your dropwizard application for exposition of [micrometer-like][micrometer] \nmetrics (system, jvm and http requests) as a [prometheus][prometheus] endpoint. In addition, if you use JDBI to manage \nmapping of objects to database tables, you can utilize [dropwizad-micrometer-jdbi](#dropwizad-micrometer-jdbi) package to meter SQL request's latencies.\n\n## Packages\n- `dropwizad-micrometer-core`\n    Dropwizard bundle that implements prometheus endpoint and exposes core system metrics and JVM metrics utilizing micrometer instrumentation.\n    Optionally, it provides servlet filter to record HTTP requests latencies and statuses within dimensional \n    [prometheus histogram][prometheus histogram].\n\n- `dropwizad-micrometer-jdbi`\n    An additional module to record latencies of [JDBI][jdbi] queries within dimensional [prometheus histogram][prometheus histogram].\n\n## Usage\nYou can find an example of usage in the [ExampleApplication][dropwizard example application].\n\nBelow are the steps explained in more detail specifically for each package.\n\n### dropwizad-micrometer-core\nThis package provides a minimal setup, i.e. it instantiates `/prometheus` endpoint, adds system and JVM metrics utilizing \nmicrometer instrumentation, and optionally you can set up servlet filter to record HTTP requests latencies/statuses.\n\n#### Add dependency into your `pom.xml`\nIf you use `maven`, you can simply reference it in the `\u003cdependenccies\u003e` block as below. \nThe latest version can be found in [Releases](https://github.com/MaksymDolgykh/dropwizard-micrometer/releases) or in the maven [repository][dropwizard-micrometer-core maven repo]\n\n```xml\n    \u003cdependencies\u003e\n        ...\n        ...\n        \u003cdependency\u003e\n            \u003cgroupId\u003eio.github.maksymdolgykh.dropwizard\u003c/groupId\u003e\n            \u003cartifactId\u003edropwizard-micrometer-core\u003c/artifactId\u003e\n            \u003cversion\u003e2.0.5\u003c/version\u003e\n        \u003c/dependency\u003e\n        ...\n        ...\n    \u003c/dependencies\u003e\n\n\n```\n#### Import DropwizardMicrometer classes in your Application class\n```java\nimport io.github.maksymdolgykh.dropwizard.micrometer.MicrometerBundle;\nimport io.github.maksymdolgykh.dropwizard.micrometer.MicrometerHttpFilter;\nimport javax.servlet.FilterRegistration;\nimport javax.servlet.DispatcherType;\nimport java.util.EnumSet;\n```\n\n\n#### Add the bundle to your application\n\nAdd `MicrometerBundle` class to the bootstrapping phase of your Application class\n\n```java\npublic class ExampleApplication extends Application\u003cExampleConfiguration\u003e {\n    //...\n    //...\n\n    @Override\n    public void initialize(Bootstrap\u003cExampleConfiguration\u003e bootstrap) {\n        //...\n        //...\n        bootstrap.addBundle(new MicrometerBundle());\n        //...\n        //...\n    }\n    //...\n    //...\n}\n```\n\nYou will also need to make your `ExampleConfiguration` class implement `MicrometerBundleConfiguration` \nin order to provide the bundle with the configuration:\n```java\npublic class ExampleConfiguration extends Configuration implements MicrometerBundleConfiguration {\n    @JsonProperty(\"prometheus\")\n    private PrometheusConfiguration prometheusConfiguration = new PrometheusConfiguration();\n\n    @Override\n    public PrometheusConfiguration getPrometheusConfiguration() {\n        return prometheusConfiguration;\n    }\n    //...\n    //...\n}\n```\nAssuming, the above example, configuration element is `prometheus`, so you can use configuration block like this in a config file:\n```yaml\nprometheus:\n  endpoint: \"/prometheus\"\n```\n\nThis will expose `/prometheus` endpoint in admin connector, by default admin connector is exposed at port `8081` \nin dropwizard apps.\n\n### Assign servlet filter to the environment\n\nTo leverage latency metrics per http endpoint you need to assign servlet filter to the environment \nin your Application class within `run` method\n```java\npublic class ExampleApplication extends Application\u003cExampleConfiguration\u003e {\n    //...\n    //...\n    @Override\n    public void run(ExampleConfiguration configuration, Environment environment) {\n        //...\n        //...\n        FilterRegistration.Dynamic micrometerFilter = environment.servlets().addFilter(\"MicrometerHttpFilter\", new MicrometerHttpFilter());\n        micrometerFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, \"/*\");\n    }\n}\n```\nThis way all http requests will be metered and metrics will be recorded within `http_server_requests_seconds` [histogram][prometheus histogram] \nwith the following labels:\n- `method`, http method, i.e. `GET`, `POST` etc\n- `status`, response status, i.e. `200`, `404`, `500` etc\n- `uri`, request path\n\n\n### dropwizad-micrometer-jdbi\nIf you use [JDBI][jdbi] to manage mapping of objects to database tables, you can utilize \n[dropwizad-micrometer-jdbi][dropwizard-micrometer-jdbi maven repo] package to meter SQL request's latencies. \nIt depends on `dropwizad-micrometer-core`, so that to use `dropwizad-micrometer-jdbi` package\nthe core package should be already installed and bundle should be added to your dropwizard application\n(see how to install it in [dropwizad-micrometer-core](#dropwizad-micrometer-core) section). \nOnce `dropwizad-micrometer-core` is installed, the steps to install `dropwizad-micrometer-jdbi` package are:\n\n#### Add dependency into your `pom.xml`\nIf you use `maven`, you can simply reference it in the `\u003cdependenccies\u003e` block as below. \nThe latest version can be found on in the maven [repository][dropwizard-micrometer-jdbi maven repo]\n\n```xml\n \u003cdependencies\u003e\n     ...\n     ...\n     \u003cdependency\u003e\n         \u003cgroupId\u003eio.github.maksymdolgykh.dropwizard\u003c/groupId\u003e\n         \u003cartifactId\u003edropwizard-micrometer-jdbi\u003c/artifactId\u003e\n         \u003cversion\u003e2.0.5\u003c/version\u003e\n     \u003c/dependency\u003e\n     ...\n     ...\n \u003c/dependencies\u003e\n\n ```\n\n#### Import MicrometerJdbiTimingCollector class in your Application class\n ```java\nimport io.github.maksymdolgykh.dropwizard.micrometer.MicrometerJdbiTimingCollector;\n ```\n\n#### Set TimingColletor for Jdbi object\nTo use the class you just need to set `TimingColletor` for Jdbi object, where it should be done depends on how your \nApplication is organized - it might be in the `run` method of your `Application` class, or you might have separate \nclass to configure DAO.\n```\ndatabase.setTimingCollector(new MicrometerJdbiTimingCollector());\n```\nWith this setup all jdbi requests will be metered and metrics will be recorded within `jdbi_requests_seconds` [histogram][prometheus histogram]\n\n## License\nThis project is licensed under the Apache License 2.0 ([LICENSE](./LICENSE.TXT))\n\n\n[dropwizard]: https://www.dropwizard.io/en/latest/\n[dropwizard example application]: https://github.com/MaksymDolgykh/dropwizard-example-app\n[dropwizard-micrometer-core maven repo]: https://mvnrepository.com/artifact/io.github.maksymdolgykh.dropwizard/dropwizard-micrometer-core\n[dropwizard-micrometer-jdbi maven repo]: https://mvnrepository.com/artifact/io.github.maksymdolgykh.dropwizard/dropwizard-micrometer-jdbi\n[jdbi]: https://jdbi.org/\n[micrometer]: http://micrometer.io/\n[prometheus]: https://prometheus.io/\n[prometheus histogram]: https://prometheus.io/docs/practices/histograms/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksymdolgykh%2Fdropwizard-micrometer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaksymdolgykh%2Fdropwizard-micrometer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksymdolgykh%2Fdropwizard-micrometer/lists"}