{"id":15044407,"url":"https://github.com/elastic/elasticsearch-metrics-reporter-java","last_synced_at":"2025-04-06T01:09:50.850Z","repository":{"id":9836851,"uuid":"11826393","full_name":"elastic/elasticsearch-metrics-reporter-java","owner":"elastic","description":"Metrics reporter, which reports to elasticsearch","archived":false,"fork":false,"pushed_at":"2024-08-08T07:45:10.000Z","size":106,"stargazers_count":231,"open_issues_count":24,"forks_count":104,"subscribers_count":356,"default_branch":"master","last_synced_at":"2025-03-30T00:07:45.298Z","etag":null,"topics":[],"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/elastic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-08-01T19:59:55.000Z","updated_at":"2024-10-07T21:21:52.000Z","dependencies_parsed_at":"2022-09-24T06:11:15.457Z","dependency_job_id":"d2419ce3-3825-4be1-a2cd-ac403a53230c","html_url":"https://github.com/elastic/elasticsearch-metrics-reporter-java","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Felasticsearch-metrics-reporter-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Felasticsearch-metrics-reporter-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Felasticsearch-metrics-reporter-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Felasticsearch-metrics-reporter-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elastic","download_url":"https://codeload.github.com/elastic/elasticsearch-metrics-reporter-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419861,"owners_count":20936012,"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":[],"created_at":"2024-09-24T20:50:33.098Z","updated_at":"2025-04-06T01:09:50.827Z","avatar_url":"https://github.com/elastic.png","language":"Java","funding_links":[],"categories":["指标库"],"sub_categories":["Spring Cloud框架"],"readme":"# Metrics Elasticsearch Reporter\n\n![Project unmaintained](https://img.shields.io/badge/project-unmaintained-red.svg)\n\n**This project is no longer maintained. If you want to maintain it, please fork and we will link to your new repository.**\n\n## Introduction\n\nThis is a reporter for the excellent [Metrics library](http://metrics.dropwizard.io/), similar to the [Graphite](http://metrics.dropwizard.io/3.1.0/manual/graphite/) or [Ganglia](http://metrics.dropwizard.io/3.1.0/manual/ganglia/) reporters, except that it reports to an Elasticsearch server.\n\nIn case, you are worried, that you need to include the 20MB elasticsearch dependency in your project, you do not need to be. As this reporter is using HTTP for putting data into elasticsearch, the only library needed is the awesome [Jackson JSON library](http://wiki.fasterxml.com/JacksonHome), more exactly the Jackson Databind library to easily serialize the metrics objects.\n\nIf you want to see this in action, go to the `samples/` directory and read the readme over there, to get up and running with a sample application using the Metrics library as well as a dashboard application to graph.\n\n## Compatibility\n\n|   Metrics-elasticsearch-reporter  |    elasticsearch    | Release date |\n|-----------------------------------|---------------------|:------------:|\n| 2.3.0-SNAPSHOT                    | 2.3.0  -\u003e master    |  NONE        |\n| 2.2.0                             | 2.2.0  -\u003e 2.2.x     |  2016-02-10  |\n| 2.0                               | 1.0.0  -\u003e 1.7.x     |  2014-02-16  |\n| 1.0                               | 0.90.7 -\u003e 0.90.x    |  2014-02-05  |\n\n## Travis CI build status\n\n[![Build status](https://api.travis-ci.org/elastic/elasticsearch-metrics-reporter-java.svg?branch=master)](https://travis-ci.org/elastic/elasticsearch-metrics-reporter-java)\n\n## Installation\n\nYou can simply add a dependency in your `pom.xml` (or whatever dependency resolution system you might have)\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.elasticsearch\u003c/groupId\u003e\n  \u003cartifactId\u003emetrics-elasticsearch-reporter\u003c/artifactId\u003e\n  \u003cversion\u003e2.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Configuration\n\n```\nfinal MetricRegistry registry = new MetricRegistry();\nElasticsearchReporter reporter = ElasticsearchReporter.forRegistry(registry)\n    .hosts(\"localhost:9200\", \"localhost:9201\")\n    .build();\nreporter.start(60, TimeUnit.SECONDS);\n```\n\nDefine your metrics and registries as usual\n\n```\nprivate final Meter incomingRequestsMeter = registry.meter(\"incoming-http-requests\");\n\n// in your app code\nincomingRequestsMeter.mark(1);\n```\n\n\n### Options\n\n* `hosts()`: A list of hosts used to connect to, must be in the format `hostname:port`, default is `localhost:9200`\n* `timeout()`: Milliseconds to wait for an established connections, before the next host in the list is tried. Defaults to `1000`\n* `bulkSize()`: Defines how many metrics are sent per bulk requests, defaults to `2500`\n* `filter()`: A `MetricFilter` to define which metrics written to the elasticsearch\n* `percolationFilter()`: A `MetricFilter` to define which metrics should be percolated against. See below for an example\n* `percolationNotifier()`: An implementation of the `Notifier` interface, which is executed upon a matching percolator. See below for an example.\n* `index()`: The name of the index to write to, defaults to `metrics`\n* `indexDateFormat()`: The date format to make sure to rotate to a new index, defaults to `yyyy-MM`\n* `timestampFieldname()`: The field name of the timestamp, defaults to `@timestamp`, which makes it easy to use with kibana\n\n### Mapping\n\n**Note**: The reporter automatically checks for the existence of an index template called `metrics_template`. If this template does not exist, it is created. This template ensures that all strings used in metrics are set to `not_analyzed` and disables the `_all` field.\n\n\n## Notifications with percolations\n\n```\nElasticsearchReporter reporter = ElasticsearchReporter.forRegistry(registry)\n    .percolationNotifier(new PagerNotifier())\n    .percolationFilter(MetricFilter.ALL)\n    .build();\nreporter.start(60, TimeUnit.SECONDS);\n```\n\nWrite a custom notifier\n\n```\npublic class PagerNotifier implements Notifier {\n\n  @Override\n  public void notify(JsonMetrics.JsonMetric jsonMetric, String percolateMatcher) {\n    // send pager duty here\n  }\n}\n```\n\nAdd a percolation\n\n```\ncurl http://localhost:9200/metrics/.percolator/http-monitor -X PUT -d '{\n  \"query\" : { \n    \"bool\" : { \n      \"must\": [\n        { \"term\": { \"name\" : \"incoming-http-requests\" } },\n        { \"range\": { \"m1_rate\": { \"to\" : \"10\" } } }\n      ]\n    }\n  }\n}'\n```\n\n## JSON Format of metrics\n\nThis is how the serialized metrics looks like in elasticsearch\n\n### Counter\n\n```\n{\n  \"name\": \"usa-gov-heartbearts\",\n  \"@timestamp\": \"2013-07-20T09:29:58.000+0000\",\n  \"count\": 18\n}\n```\n\n### Timer\n\n```\n{\n  \"name\" : \"bulk-request-timer\",\n  \"@timestamp\" : \"2013-07-20T09:43:58.000+0000\",\n  \"count\" : 114,\n  \"max\" : 109.681,\n  \"mean\" : 5.439666666666667,\n  \"min\" : 2.457,\n  \"p50\" : 4.3389999999999995,\n  \"p75\" : 5.0169999999999995,\n  \"p95\" : 8.37175,\n  \"p98\" : 9.6832,\n  \"p99\" : 94.68429999999942,\n  \"p999\" : 109.681,\n  \"stddev\" : 9.956913151098842,\n  \"m15_rate\" : 0.10779994503690074,\n  \"m1_rate\" : 0.07283351433589833,\n  \"m5_rate\" : 0.10101298115113727,\n  \"mean_rate\" : 0.08251056571678642,\n  \"duration_units\" : \"milliseconds\",\n  \"rate_units\" : \"calls/second\"\n}\n```\n\n### Meter\n\n```\n{\n  \"name\" : \"usagov-incoming-requests\",\n  \"@timestamp\" : \"2013-07-20T09:29:58.000+0000\",\n  \"count\" : 224,\n  \"m1_rate\" : 0.3236309568191993,\n  \"m5_rate\" : 0.45207208204948995,\n  \"m15_rate\" : 0.5014348927301423,\n  \"mean_rate\" : 0.4135529888278531,\n  \"units\" : \"events/second\"\n}\n```\n\n### Histogram\n\n```\n{\n  \"name\" : \"my-histgram\",\n  \"@timestamp\" : \"2013-07-20T09:29:58.000+0000\",\n  \"count\" : 114,\n  \"max\" : 109.681,\n  \"mean\" : 5.439666666666667,\n  \"min\" : 2.457,\n  \"p50\" : 4.3389999999999995,\n  \"p75\" : 5.0169999999999995,\n  \"p95\" : 8.37175,\n  \"p98\" : 9.6832,\n  \"p99\" : 94.68429999999942,\n  \"p999\" : 109.681,\n  \"stddev\" : 9.956913151098842,}\n}\n```\n\n### Gauge\n\n```\n{\n  \"name\" : \"usagov-incoming-requests\",\n  \"@timestamp\" : \"2013-07-20T09:29:58.000+0000\",\n  \"value\" : 123\n}\n```\n\n\n## Next steps\n\n* Integration with Kibana would be awesome\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felastic%2Felasticsearch-metrics-reporter-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felastic%2Felasticsearch-metrics-reporter-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felastic%2Felasticsearch-metrics-reporter-java/lists"}