Initial Commit of Elasticsearch Reporter
More configuration options will follow.
Change-Id: Ibf33eec40991b9cd0a5b8917d1eefa56fd58200a
diff --git a/BUCK b/BUCK
new file mode 100644
index 0000000..c7bdf16
--- /dev/null
+++ b/BUCK
@@ -0,0 +1,50 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+include_defs('//lib/maven.defs')
+
+gerrit_plugin(
+ name = 'metrics-reporter-elasticsearch',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/resources/**/*']),
+ deps = [
+ '//lib/dropwizard:dropwizard-core',
+ ':metrics-elasticsearch-reporters',
+ ':jackson-databind',
+ ':jackson-core'
+ ],
+ manifest_entries = [
+ 'Gerrit-PluginName: metrics-reporter-elasticsearch',
+ ],
+)
+
+maven_jar(
+ name = 'metrics-elasticsearch-reporters',
+ id = 'org.elasticsearch:metrics-elasticsearch-reporter:2.0',
+ sha1 = '399ff7b3378e94be017f475a114227acc41b7b31',
+ license = 'Apache2.0',
+ deps = [ ':jackson-databind', ':jackson-core' ],
+)
+maven_jar(
+ name = 'jackson-databind',
+ id = 'com.fasterxml.jackson.core:jackson-databind:2.2.3',
+ sha1 = '03ae380888029daefb91d3ecdca3a37d8cb92bc9',
+ deps = [ ':jackson-core', ':jackson-annotations' ],
+ license = 'Apache2.0',
+)
+maven_jar(
+ name = 'jackson-core',
+ id = 'com.fasterxml.jackson.core:jackson-core:2.2.3',
+ sha1 = '1a0113da2cab5f4c216b4e5e7c1dbfaa67087e14',
+ license = 'Apache2.0',
+)
+maven_jar(
+ name = 'jackson-annotations',
+ id = 'com.fasterxml.jackson.core:jackson-annotations:2.2.3',
+ sha1 = '0527fece4f23a457070a36c371a26d6c0208e1c3',
+ license = 'Apache2.0',
+)
+# this is required for bucklets/tools/eclipse/project.py to work
+java_library(
+ name = 'classpath',
+ deps = [':metrics-reporter-elasticsearch__plugin'],
+)
+
diff --git a/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritElasticsearchReporter.java b/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritElasticsearchReporter.java
new file mode 100644
index 0000000..abb933f
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritElasticsearchReporter.java
@@ -0,0 +1,64 @@
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.metricsreporters;
+
+import com.google.gerrit.extensions.annotations.Listen;
+import com.google.gerrit.extensions.annotations.PluginName;
+import com.google.gerrit.extensions.events.LifecycleListener;
+import com.google.gerrit.server.config.PluginConfigFactory;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+import com.codahale.metrics.MetricRegistry;
+
+import org.eclipse.jgit.lib.Config;
+import org.elasticsearch.metrics.ElasticsearchReporter;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+@Listen
+@Singleton
+public class GerritElasticsearchReporter implements LifecycleListener {
+ private final ElasticsearchReporter reporter;
+
+ @Inject
+ public GerritElasticsearchReporter(
+ PluginConfigFactory configFactory,
+ @PluginName String pluginName,
+ MetricRegistry registry) {
+ Config config = configFactory.getGlobalPluginConfig(pluginName);
+ String[] hosts = config.getStringList("elasticsearch", null, "host");
+ if (hosts.length == 0) {
+ hosts = new String[] { "localhost:9200" };
+ }
+ try {
+ reporter = ElasticsearchReporter.forRegistry(registry)
+ .hosts(hosts)
+ .build();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void start() {
+ reporter.start(60, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void stop() {
+ reporter.stop();
+ }
+}