{"id":13695679,"url":"https://github.com/kenshoo/metrics-play","last_synced_at":"2025-04-06T11:10:32.371Z","repository":{"id":9038344,"uuid":"10800511","full_name":"kenshoo/metrics-play","owner":"kenshoo","description":"Metrics module for Play2","archived":false,"fork":false,"pushed_at":"2024-07-21T21:37:33.000Z","size":1116,"stargazers_count":163,"open_issues_count":6,"forks_count":73,"subscribers_count":62,"default_branch":"master","last_synced_at":"2025-03-30T09:09:05.368Z","etag":null,"topics":["managedby-tec-dev","public-repo"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenshoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-2.0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-19T17:10:22.000Z","updated_at":"2024-12-31T14:03:50.000Z","dependencies_parsed_at":"2024-12-11T08:00:24.563Z","dependency_job_id":"8e3638de-d804-4442-b67f-d387ca469517","html_url":"https://github.com/kenshoo/metrics-play","commit_stats":{"total_commits":71,"total_committers":22,"mean_commits":3.227272727272727,"dds":0.6619718309859155,"last_synced_commit":"ff666c78135205327861245963b04da33189253b"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenshoo%2Fmetrics-play","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenshoo%2Fmetrics-play/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenshoo%2Fmetrics-play/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenshoo%2Fmetrics-play/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenshoo","download_url":"https://codeload.github.com/kenshoo/metrics-play/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471521,"owners_count":20944158,"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":["managedby-tec-dev","public-repo"],"created_at":"2024-08-02T18:00:32.234Z","updated_at":"2025-04-06T11:10:32.347Z","avatar_url":"https://github.com/kenshoo.png","language":"Scala","funding_links":[],"categories":["Libraries"],"sub_categories":["Others"],"readme":"# metrics-play\n\nThis module provides some support for @codahale [Metrics](https://dropwizard.github.io/metrics/4.0.5/) library in a Play2 application (Scala)\n\n[![Build Status](https://travis-ci.org/kenshoo/metrics-play.png)](https://travis-ci.org/kenshoo/metrics-play)\n\n[![codecov.io](https://img.shields.io/codecov/c/gh/kenshoo/metrics-play/master.svg)](https://codecov.io/github/kenshoo/metrics-play/branch/master)\n\nPlay Version: 2.7.0, Metrics Version: 4.0.5, Scala Versions: 2.12.8\n\n## Features\n\n1. Default Metrics Registry\n2. Metrics Servlet\n3. Filter to instrument http requests\n\n\n## Usage\n\nAdd metrics-play dependency:\n\n```scala\n    val appDependencies = Seq(\n    ...\n    \"com.kenshoo\" %% \"metrics-play\" % \"2.7.3_0.8.2\"\n    )\n```\n\nTo enable the module:\n\nadd to application.conf the following line\n\n     play.modules.enabled+=\"com.kenshoo.play.metrics.PlayModule\"\n\n### Default Registry\n\nTo add a custom metrics, you can use `defaultRegistry` which returns an instance of [MetricRegistry](https://metrics.dropwizard.io/4.0.5/manual/core).\n\n```scala\n     import com.kenshoo.play.metrics.Metrics\n     import com.codahale.metrics.Counter\n\n     class SomeController @Inject() (metrics: Metrics) {\n         val counter = metrics.defaultRegistry.counter(\"name\")\n         counter.inc()\n     }\n````\n\n### Metrics Controller\n\nAn implementation of the [metrics-servlet](https://metrics.dropwizard.io/4.0.5/manual/servlets#metricsservlet) as a play2 controller.\n\nIt exports all registered metrics as a json document.\n\nTo enable the controller add a mapping to conf/routes file\n\n     GET     /admin/metrics              com.kenshoo.play.metrics.MetricsController.metrics\n\n#### Configuration\nSome configuration is supported through the default configuration file:\n\n    metrics.rateUnit - (default is SECONDS)\n\n    metrics.durationUnit (default is SECONDS)\n\n    metrics.showSamples [true/false] (default is false)\n\n    metrics.jvm - [true/false] (default is true) controls reporting jvm metrics\n\n    metrics.logback - [true/false] (default is true) controls reporing logback metrics\n\n### Metrics Filter\n\nAn implementation of the Metrics' instrumenting filter for Play2. It records requests duration, number of active requests and counts each return code\n\n\n```scala\n    import com.kenshoo.play.metrics.MetricsFilter\n    import play.api.mvc._\n\n    class Filters @Inject() (metricsFilter: MetricsFilter) extends HttpFilters {\n        val filters = Seq(metricsFilter)\n    }\n```\n\n## Advanced usage\n\nBy default, metrics are prefixed with \"com.kenshoo.play.metrics.MetricsFilter\".\n\n```\n\"com.kenshoo.play.metrics.MetricsFilter.200\" : {\n   \"count\" : 1584456,\n   \"m15_rate\" : 1.6800220918042639,\n   \"m1_rate\" : 1.9015104460758263,\n   \"m5_rate\" : 1.8138545372237085,\n   \"mean_rate\" : 3.20162010446889,\n   \"units\" : \"events/second\"\n},\n```\n\nYou can change the prefix by extending `MetricsFilterImpl`.\n\n```scala\npackage myapp\n\nimport javax.inject.Inject\n\nimport com.kenshoo.play.metrics.{MetricsImpl, MetricsFilter, Metrics, MetricsFilterImpl}\nimport play.api.http.Status\nimport play.api.inject.Module\nimport play.api.{Configuration, Environment}\n\nclass MyMetricsFilter @Inject() (metrics: Metrics) extends MetricsFilterImpl(metrics) {\n\n  // configure metrics prefix\n  override def labelPrefix: String = \"foobar\"\n\n  // configure status codes to be monitored. other status codes are labeled as \"other\"\n  override def knownStatuses = Seq(Status.OK)\n}\n\nclass MyMetricsModule extends Module {\n  def bindings(environment: Environment, configuration: Configuration) = {\n    Seq(\n      bind[MetricsFilter].to[MyMetricsFilter].eagerly,\n      bind[Metrics].to[MetricsImpl].eagerly\n    )\n  }\n}\n```\n\nand add the following line to application.conf\n\n```\nplay.modules.enabled+=\"myapp.MyMetricsModule\"\n```\n\n## Changes\n\n* 2.7.3_0.8.2 - Minor compatability fix for Play 2.8\n* 2.7.3_0.8.1 - Upgrade to play 2.7.3 and support Scala version 2.12.8 / 2.13.0 with dropwizard 4.0.5\n* 2.7.0_0.8.0 - Upgrade to play 2.7.0 and Scala 2.12.8 and dropwizard 4.0.5\n* 2.6.19_0.7.0 - Upgrade to play 2.6.19 and Scala 2.12.6 and dropwizard 4.0.3\n* 2.6.2_0.6.1 - Upgrade to play 2.6 and Scala 2.12. Migration: If you get errors like \"No configuration setting found ...\" when building fat JARs, check your merge strategy for reference.conf.\n* 2.4.0_0.4.0 - Re-implement as Play Module\n* 2.4.0_0.3.0 - Upgrade to play 2.4, metrics 3.1.2\n* 2.3.0_0.2.1 - Breaking Change! prefix jvm metric names to standardize with dropwizard\n* 2.3.0_0.2.0 - Meter uncaught exceptions as 500 Internal Server Error\n* 2.3.0_0.1.9 - Add extra http codes, support configurable metrics names for requests filter\n* 2.3.0_0.1.8 - Support default registry in play java. Replace MetricsRegistry.default with MetricsRegistry.defaultRegistry (to support java where default is a reserved keyword)\n\n\n## License\nThis code is released under the Apache Public License 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenshoo%2Fmetrics-play","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenshoo%2Fmetrics-play","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenshoo%2Fmetrics-play/lists"}