JMX Reporter for Gerrit's Metrics Registry Change-Id: I8fbaa491e88ccda2e88c040f38edc833ba345013
diff --git a/BUCK b/BUCK new file mode 100644 index 0000000..419c77e --- /dev/null +++ b/BUCK
@@ -0,0 +1,22 @@ +include_defs('//bucklets/gerrit_plugin.bucklet') +include_defs('//lib/maven.defs') + +gerrit_plugin( + name = 'metrics-reporter-jmx', + srcs = glob(['src/main/java/**/*.java']), + resources = glob(['src/main/resources/**/*']), + deps = [ + '//lib/dropwizard:dropwizard-core' + ], + manifest_entries = [ + 'Gerrit-PluginName: metrics-reporter-jmx', + ], +) + +# this is required for bucklets/tools/eclipse/project.py to work +java_library( + name = 'classpath', + deps = [':metrics__plugin'], +) + +
diff --git a/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritJmxReporter.java b/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritJmxReporter.java new file mode 100644 index 0000000..2a9a3d7 --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritJmxReporter.java
@@ -0,0 +1,43 @@ +// 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.events.LifecycleListener; +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import com.codahale.metrics.JmxReporter; +import com.codahale.metrics.MetricRegistry; + +@Listen +@Singleton +public class GerritJmxReporter implements LifecycleListener { + private final JmxReporter reporter; + + @Inject + public GerritJmxReporter(MetricRegistry registry) { + this.reporter = JmxReporter.forRegistry(registry).build(); + } + + @Override + public void start() { + reporter.start(); + } + + @Override + public void stop() { + reporter.stop(); + } +}