├── .gitignore
├── .travis.yml
├── .travis
├── script.sh
└── settings.xml
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── dhatim
│ │ └── io
│ │ └── dropwizard
│ │ └── metrics
│ │ └── elasticsearch
│ │ └── ElasticSearchReporterFactory.java
└── resources
│ └── META-INF
│ └── services
│ └── io.dropwizard.metrics.ReporterFactory
└── test
└── java
└── org
└── dhatim
└── io
└── dropwizard
└── metrics
└── elasticsearch
└── ElasticSearchReporterFactoryTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk: oraclejdk8
3 | install: true
4 | script: . .travis/script.sh
5 |
--------------------------------------------------------------------------------
/.travis/script.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | if [ "${TRAVIS_EVENT_TYPE}" == push ] &&
4 | echo "${TRAVIS_TAG}" | egrep '^[0-9]+\.[0-9]+\.[0-9]+$'
5 | then
6 | # the build is triggered by a tag push, and the tag looks like
7 | # a version number: proceed with release
8 | echo ${GPG_SECRET_KEY} | base64 --decode | gpg --import
9 | echo ${GPG_OWNERTRUST} | base64 --decode | gpg --import-ownertrust
10 | mvn versions:set -DnewVersion=${TRAVIS_TAG}
11 | mvn -s .travis/settings.xml -Prelease deploy
12 | else
13 | # this is a regular build
14 | mvn install
15 | fi
16 |
--------------------------------------------------------------------------------
/.travis/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ossrh
5 | ${env.SONATYPE_USERNAME}
6 | ${env.SONATYPE_PASSWORD}
7 |
8 |
9 |
10 |
11 | ossrh
12 |
13 | true
14 |
15 |
16 | ${env.GPG_PASSPHRASE}
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2015 Dhatim
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dropwizard Metrics Support for Elastic Search
2 |
3 | [](https://travis-ci.org/dhatim/dropwizard-metrics-elasticsearch)
4 | [](https://maven-badges.herokuapp.com/maven-central/org.dhatim.io.dropwizard/dropwizard-metrics-elasticsearch)
5 |
6 | This modules enables a [dropwizard][dw] application to send
7 | [metrics][dwm] to an [elasticsearch][e] instance.
8 |
9 | ## What about [Metrics Elasticsearch Reporter][mer]? Doesn't it do just that?
10 |
11 | [No, it doesn't][dwi]. As outlined [here][merc], it needs you to write
12 | some code in your application. This module adds the ability to perform
13 | that task through your dropwizard application yaml configuration. In
14 | fact, under the hood it actually makes use of
15 | [Metrics Elasticsearch Reporter][mer] to perform the work.
16 |
17 | ## How to
18 |
19 | - add this jar as a dependency to the dropwizard app:
20 |
21 | ```xml
22 |
23 | ../..
24 |
25 | org.dhatim.io.dropwizard
26 | dropwizard-metrics-elasticsearch
27 | 1.0.8
28 |
29 | ../..
30 |
31 | ```
32 |
33 | - enable the metrics reporter through the configuration:
34 |
35 | ```yaml
36 | metrics:
37 | reporters:
38 | - type: elasticsearch
39 | ```
40 |
41 | and you're good to go.
42 |
43 | ## configuration
44 |
45 | The configuration is somewhat limited right now:
46 |
47 | - servers: you can configure a set of elasticsearch nodes with the
48 | `servers` key, which hold a collection of `host` and `port` keys.
49 | - prefix: useful to identify single hosts.
50 | - index: elasticsearch index name.
51 | - indexDateFormat: elasticsearch index date format.
52 | - additionalFields: optional map of additional field values.
53 |
54 | ### default values
55 |
56 | ```yaml
57 | metrics:
58 | reporters:
59 | - type: elasticsearch
60 | servers:
61 | - host: localhost
62 | port: 9200
63 | prefix:
64 | index: metrics
65 | indexDateFormat: yyyy.MM.dd
66 | additionalFields:
67 | ```
68 |
69 | It should basically follow the [Metrics Elasticsearch Reporter][mer]
70 | defaults.
71 |
72 | [dw]: http://www.dropwizard.io
73 | [dwm]: http://metrics.dropwizard.io
74 | [e]: https://www.elastic.co/products/elasticsearch
75 | [mer]: https://github.com/elastic/elasticsearch-metrics-reporter-java
76 | [dwi]: https://github.com/dropwizard/dropwizard/issues/1277
77 | [merc]: https://github.com/elastic/elasticsearch-metrics-reporter-java#configuration
78 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.dhatim.io.dropwizard
6 | dropwizard-metrics-elasticsearch
7 | 0-SNAPSHOT
8 |
9 | ${project.groupId}:${project.artifactId}
10 | Dropwizard Metrics Support for Elastic Search
11 | https://github.com/dhatim/dropwizard-metrics-elasticsearch
12 |
13 |
14 |
15 | The Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 |
18 |
19 |
20 |
21 |
22 | Dhatim
23 | http://dhatim.com
24 |
25 |
26 |
27 |
28 | scm:git:git://github.com/dhatim/dropwizard-metrics-elasticsearch.git
29 | scm:git:ssh://github.com:dhatim/dropwizard-metrics-elasticsearch.git
30 | https://github.com/dhatim/dropwizard-metrics-elasticsearch/tree/${project.version}
31 |
32 |
33 |
34 |
35 | ossrh
36 | https://oss.sonatype.org/content/repositories/snapshots
37 |
38 |
39 |
40 |
41 | 3.0.4
42 |
43 |
44 |
45 | 1.8
46 | 1.8
47 | UTF-8
48 | UTF-8
49 |
50 |
51 |
52 |
53 |
54 |
55 | maven-clean-plugin
56 | 3.0.0
57 |
58 |
59 | maven-compiler-plugin
60 | 3.5.1
61 |
62 |
63 | maven-deploy-plugin
64 | 2.8.2
65 |
66 |
67 | maven-gpg-plugin
68 | 1.6
69 |
70 |
71 | maven-install-plugin
72 | 2.5.2
73 |
74 |
75 | maven-jar-plugin
76 | 3.0.2
77 |
78 |
79 | maven-javadoc-plugin
80 | 2.10.4
81 |
82 |
83 | maven-resources-plugin
84 | 3.0.1
85 |
86 |
87 | maven-site-plugin
88 | 3.5.1
89 |
90 |
91 | maven-source-plugin
92 | 3.0.1
93 |
94 |
95 | maven-surefire-plugin
96 | 2.19.1
97 |
98 |
99 | org.sonatype.plugins
100 | nexus-staging-maven-plugin
101 | 1.6.7
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | release
110 |
111 |
112 |
113 | maven-gpg-plugin
114 |
115 |
116 | sign-artifacts
117 | verify
118 |
119 | sign
120 |
121 |
122 |
123 |
124 |
125 | maven-javadoc-plugin
126 |
127 | true
128 |
129 |
130 |
131 | attach-javadocs
132 |
133 | jar
134 |
135 |
136 |
137 |
138 |
139 | maven-source-plugin
140 |
141 |
142 | attach-sources
143 |
144 | jar-no-fork
145 |
146 |
147 |
148 |
149 |
150 | org.sonatype.plugins
151 | nexus-staging-maven-plugin
152 | true
153 |
154 | ossrh
155 | https://oss.sonatype.org
156 | true
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 | org.elasticsearch
167 | metrics-elasticsearch-reporter
168 | 2.2.0
169 |
170 |
171 | com.codahale.metrics
172 | metrics-core
173 |
174 |
175 | com.fasterxml.jackson.core
176 | jackson-databind
177 |
178 |
179 |
180 |
181 | io.dropwizard
182 | dropwizard-metrics
183 | 1.0.2
184 | provided
185 |
186 |
187 | junit
188 | junit
189 | 4.12
190 | test
191 |
192 |
193 | org.assertj
194 | assertj-core
195 | 3.5.2
196 | test
197 |
198 |
199 |
200 |
--------------------------------------------------------------------------------
/src/main/java/org/dhatim/io/dropwizard/metrics/elasticsearch/ElasticSearchReporterFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Dhatim
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.dhatim.io.dropwizard.metrics.elasticsearch;
17 |
18 | import com.codahale.metrics.MetricRegistry;
19 | import com.codahale.metrics.ScheduledReporter;
20 | import com.fasterxml.jackson.annotation.JsonTypeName;
21 | import io.dropwizard.metrics.BaseReporterFactory;
22 | import java.io.IOException;
23 | import java.util.Arrays;
24 | import java.util.Map;
25 | import org.elasticsearch.metrics.ElasticsearchReporter;
26 | import org.hibernate.validator.constraints.NotEmpty;
27 | import org.hibernate.validator.constraints.Range;
28 |
29 | @JsonTypeName("elasticsearch")
30 | public class ElasticSearchReporterFactory extends BaseReporterFactory {
31 |
32 | public static class Server {
33 |
34 | @NotEmpty
35 | public String host = "localhost";
36 |
37 | @Range(min = 1, max = 49151)
38 | public int port = 9200;
39 |
40 | public Server() {
41 | }
42 |
43 | public Server(String host, int port) {
44 | this.host = host;
45 | this.port = port;
46 | }
47 | }
48 |
49 | public Server[] servers = new Server[]{new Server("localhost", 9200)};
50 |
51 | public String prefix = "";
52 |
53 | public String index = "metrics";
54 |
55 | public String indexDateFormat = "yyyy.MM.dd";
56 |
57 | public Map additionalFields;
58 |
59 | @Override
60 | public ScheduledReporter build(MetricRegistry registry) {
61 | try {
62 | String[] hosts = Arrays.stream(servers)
63 | .map(s -> s.host + ":" + s.port)
64 | .toArray(String[]::new);
65 |
66 | return ElasticsearchReporter.forRegistry(registry)
67 | .hosts(hosts)
68 | .prefixedWith(prefix)
69 | .index(index)
70 | .indexDateFormat(indexDateFormat)
71 | .additionalFields(additionalFields)
72 | .build();
73 | } catch (IOException e) {
74 | throw new RuntimeException("can't build elasticsearch reporter", e);
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/services/io.dropwizard.metrics.ReporterFactory:
--------------------------------------------------------------------------------
1 | org.dhatim.io.dropwizard.metrics.elasticsearch.ElasticSearchReporterFactory
--------------------------------------------------------------------------------
/src/test/java/org/dhatim/io/dropwizard/metrics/elasticsearch/ElasticSearchReporterFactoryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Dhatim
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.dhatim.io.dropwizard.metrics.elasticsearch;
17 |
18 | import io.dropwizard.jackson.DiscoverableSubtypeResolver;
19 | import static org.assertj.core.api.Assertions.assertThat;
20 | import org.junit.Test;
21 |
22 | public class ElasticSearchReporterFactoryTest {
23 |
24 | @Test
25 | public void isDiscoverable() throws Exception {
26 | assertThat(new DiscoverableSubtypeResolver().getDiscoveredSubtypes())
27 | .contains(ElasticSearchReporterFactory.class);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------