You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/02/03 09:44:34 UTC
[06/12] james-project git commit: JAMES-1901 Move ES metrics reporter
to a dedicated project
JAMES-1901 Move ES metrics reporter to a dedicated project
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ea114d7a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ea114d7a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ea114d7a
Branch: refs/heads/master
Commit: ea114d7a0e31ca1eb8b88076efcd03fa8c0d5e4e
Parents: 6f38dcb
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 23 14:14:58 2017 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Feb 3 16:43:35 2017 +0700
----------------------------------------------------------------------
server/container/guice/cassandra-guice/pom.xml | 5 +
.../modules/server/ESMetricReporterModule.java | 17 +-
.../metrics/metrics-dropwizard/pom.xml | 4 -
.../dropwizard/DropWizardMetricFactory.java | 10 +-
.../metrics/dropwizard/ESMetricReporter.java | 69 -------
.../dropwizard/ESReporterConfiguration.java | 81 --------
.../metrics/metrics-es-reporter/pom.xml | 205 +++++++++++++++++++
.../james/metrics/es/ESMetricReporter.java | 69 +++++++
.../metrics/es/ESReporterConfiguration.java | 82 ++++++++
.../META-INF/org/apache/james/spring-server.xml | 6 +-
server/pom.xml | 1 +
11 files changed, 376 insertions(+), 173 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/guice/cassandra-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml
index f4699c3..522d6bc 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -235,6 +235,11 @@
<artifactId>james-server-data-jmap-cassandra</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>metrics-es-reporter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
index fcf0eb7..06cf7a7 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
@@ -21,7 +21,7 @@ package org.apache.james.modules.server;
import java.io.FileNotFoundException;
import java.util.List;
-import java.util.concurrent.ExecutionException;
+import java.util.Optional;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -29,15 +29,13 @@ import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.NotImplementedException;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
-import org.apache.james.metrics.dropwizard.ESMetricReporter;
-import org.apache.james.metrics.dropwizard.ESReporterConfiguration;
+import org.apache.james.metrics.es.ESMetricReporter;
+import org.apache.james.metrics.es.ESReporterConfiguration;
import org.apache.james.modules.mailbox.ElasticSearchMailboxModule;
import org.apache.james.utils.ConfigurationPerformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
@@ -65,8 +63,8 @@ public class ESMetricReporterModule extends AbstractModule {
return ESReporterConfiguration.enabled(
propertiesReader.getString(ElasticSearchMailboxModule.ELASTICSEARCH_MASTER_HOST),
propertiesReader.getInt("elasticsearch.http.port", DEFAULT_ES_HTTP_PORT),
- Optional.fromNullable(propertiesReader.getString("elasticsearch.metrics.reports.index", null)),
- Optional.fromNullable(propertiesReader.getLong("elasticsearch.metrics.reports.period", null)));
+ Optional.ofNullable(propertiesReader.getString("elasticsearch.metrics.reports.index", null)),
+ Optional.ofNullable(propertiesReader.getLong("elasticsearch.metrics.reports.period", null)));
}
} catch (FileNotFoundException e) {
LOGGER.info("Can not locate " + ElasticSearchMailboxModule.ES_CONFIG_FILE);
@@ -83,11 +81,6 @@ public class ESMetricReporterModule extends AbstractModule {
fileSystem.getFile(ElasticSearchMailboxModule.ES_CONFIG_FILE));
}
- @Provides
- public ESMetricReporter provideReporter(DropWizardMetricFactory metricFactory, ESReporterConfiguration configuration) throws ConfigurationException, ExecutionException, InterruptedException {
- return metricFactory.provideEsReporter(configuration);
- }
-
@Singleton
public static class ESMetricReporterStarter implements ConfigurationPerformer, Configurable {
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-dropwizard/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/pom.xml b/server/container/metrics/metrics-dropwizard/pom.xml
index 5ad3440..3d40daf 100644
--- a/server/container/metrics/metrics-dropwizard/pom.xml
+++ b/server/container/metrics/metrics-dropwizard/pom.xml
@@ -57,10 +57,6 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
- <dependency>
- <groupId>org.elasticsearch</groupId>
- <artifactId>metrics-elasticsearch-reporter</artifactId>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
index 005ae34..4eee021 100644
--- a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
+++ b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
@@ -20,6 +20,7 @@
package org.apache.james.metrics.dropwizard;
import javax.annotation.PreDestroy;
+import javax.inject.Inject;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.metrics.api.Metric;
@@ -33,16 +34,13 @@ public class DropWizardMetricFactory implements MetricFactory {
private final MetricRegistry metricRegistry;
private final JmxReporter jmxReporter;
- public DropWizardMetricFactory() {
- this.metricRegistry = new MetricRegistry();
+ @Inject
+ public DropWizardMetricFactory(MetricRegistry metricRegistry) {
+ this.metricRegistry = metricRegistry;
this.jmxReporter = JmxReporter.forRegistry(metricRegistry)
.build();
}
- public ESMetricReporter provideEsReporter(ESReporterConfiguration esReporterConfiguration) {
- return new ESMetricReporter(esReporterConfiguration, metricRegistry);
- }
-
@Override
public Metric generate(String name) {
return new DropWizardMetric(metricRegistry.counter(name));
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESMetricReporter.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESMetricReporter.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESMetricReporter.java
deleted file mode 100644
index 6d782ce..0000000
--- a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESMetricReporter.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you 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 org.apache.james.metrics.dropwizard;
-
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-import javax.annotation.PreDestroy;
-
-import org.elasticsearch.metrics.ElasticsearchReporter;
-
-import com.codahale.metrics.MetricRegistry;
-import com.google.common.base.Optional;
-import com.google.common.base.Throwables;
-
-public class ESMetricReporter {
-
- private final Optional<ElasticsearchReporter> reporter;
- private final ESReporterConfiguration esReporterConfiguration;
-
- public ESMetricReporter(ESReporterConfiguration esReporterConfiguration, MetricRegistry registry) {
- this.reporter = getReporter(esReporterConfiguration, registry);
- this.esReporterConfiguration = esReporterConfiguration;
- }
-
- private Optional<ElasticsearchReporter> getReporter(ESReporterConfiguration esReporterConfiguration, MetricRegistry registry) {
- if (esReporterConfiguration.isEnabled()) {
- try {
- return Optional.of(ElasticsearchReporter.forRegistry(registry)
- .hosts(esReporterConfiguration.getHostWithPort())
- .index(esReporterConfiguration.getIndex())
- .build());
- } catch (IOException e) {
- throw Throwables.propagate(e);
- }
- }
- return Optional.absent();
- }
-
- public void start() {
- if (reporter.isPresent()) {
- reporter.get().start(esReporterConfiguration.getPeriodInSecond(), TimeUnit.SECONDS);
- }
- }
-
- @PreDestroy
- public void stop() {
- if (reporter.isPresent()) {
- reporter.get().stop();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESReporterConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESReporterConfiguration.java b/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESReporterConfiguration.java
deleted file mode 100644
index 06e669f..0000000
--- a/server/container/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/ESReporterConfiguration.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you 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 org.apache.james.metrics.dropwizard;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
-public class ESReporterConfiguration {
-
- public static final boolean ENABLED = true;
- public static final boolean DISABLED = !ENABLED;
- public static final String DEFAULT_INDEX = "james-metrics";
- public static final long DEFAULT_PERIOD_IN_SECOND = 60L;
-
- public static ESReporterConfiguration disabled() {
- return new ESReporterConfiguration(
- Optional.<String>absent(),
- Optional.<Integer>absent(),
- DISABLED,
- Optional.<String>absent(),
- Optional.<Long>absent());
- }
-
- public static ESReporterConfiguration enabled(String host, int port, Optional<String> index, Optional<Long> periodInSecond) {
- return new ESReporterConfiguration(
- Optional.of(host),
- Optional.of(port),
- ENABLED,
- index,
- periodInSecond);
- }
-
- private final Optional<String> host;
- private final Optional<Integer> port;
- private final boolean enabled;
- private final Optional<String> index;
- private final Optional<Long> periodInSecond;
-
- public ESReporterConfiguration(Optional<String> host, Optional<Integer> port, boolean enabled, Optional<String> index, Optional<Long> periodInSecond) {
- this.host = host;
- this.port = port;
- this.enabled = enabled;
- this.index = index;
- this.periodInSecond = periodInSecond;
- }
-
- public String getHostWithPort() {
- Preconditions.checkState(host.isPresent());
- Preconditions.checkState(port.isPresent());
- return host.get() + ":" + port.get();
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public String getIndex() {
- return index.or(DEFAULT_INDEX);
- }
-
- public long getPeriodInSecond() {
- return periodInSecond.or(DEFAULT_PERIOD_IN_SECOND);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-es-reporter/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/pom.xml b/server/container/metrics/metrics-es-reporter/pom.xml
new file mode 100644
index 0000000..5373502
--- /dev/null
+++ b/server/container/metrics/metrics-es-reporter/pom.xml
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>james-server</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.0.0-beta6-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>metrics-es-reporter</artifactId>
+
+ <profiles>
+ <profile>
+ <id>disable-build-for-older-jdk</id>
+ <activation>
+ <jdk>(,1.8)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-jar</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>jar</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>test-jar</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-compile</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>default-testCompile</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-test</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-install</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-resources</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>default-testResources</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-descriptor</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>build-for-jdk-8</id>
+ <activation>
+ <jdk>[1.8,)</jdk>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.elasticsearch</groupId>
+ <artifactId>metrics-elasticsearch-reporter</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>animal-sniffer-java-8</id>
+ <activation>
+ <jdk>[1.8,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
+ <configuration>
+ <signature>
+ <groupId>org.codehaus.mojo.signature</groupId>
+ <artifactId>java18</artifactId>
+ <version>1.0</version>
+ </signature>
+ </configuration>
+ <executions>
+ <execution>
+ <id>check_java_8</id>
+ <phase>test</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESMetricReporter.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESMetricReporter.java b/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESMetricReporter.java
new file mode 100644
index 0000000..bc81cf8
--- /dev/null
+++ b/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESMetricReporter.java
@@ -0,0 +1,69 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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 org.apache.james.metrics.es;
+
+import java.io.IOException;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+
+import org.elasticsearch.metrics.ElasticsearchReporter;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.ScheduledReporter;
+import com.google.common.base.Throwables;
+
+public class ESMetricReporter {
+
+ private final Optional<ElasticsearchReporter> reporter;
+ private final ESReporterConfiguration esReporterConfiguration;
+
+ @Inject
+ public ESMetricReporter(ESReporterConfiguration esReporterConfiguration, MetricRegistry registry) {
+ this.reporter = getReporter(esReporterConfiguration, registry);
+ this.esReporterConfiguration = esReporterConfiguration;
+ }
+
+ private Optional<ElasticsearchReporter> getReporter(ESReporterConfiguration esReporterConfiguration, MetricRegistry registry) {
+ if (esReporterConfiguration.isEnabled()) {
+ try {
+ return Optional.of(ElasticsearchReporter.forRegistry(registry)
+ .hosts(esReporterConfiguration.getHostWithPort())
+ .index(esReporterConfiguration.getIndex())
+ .build());
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+ return Optional.empty();
+ }
+
+ public void start() {
+ reporter.ifPresent(elasticsearchReporter ->
+ elasticsearchReporter.start(esReporterConfiguration.getPeriodInSecond(), TimeUnit.SECONDS));
+ }
+
+ @PreDestroy
+ public void stop() {
+ reporter.ifPresent(ScheduledReporter::stop);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESReporterConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESReporterConfiguration.java b/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESReporterConfiguration.java
new file mode 100644
index 0000000..5b7ad0f
--- /dev/null
+++ b/server/container/metrics/metrics-es-reporter/src/main/java/org/apache/james/metrics/es/ESReporterConfiguration.java
@@ -0,0 +1,82 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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 org.apache.james.metrics.es;
+
+import java.util.Optional;
+
+import com.google.common.base.Preconditions;
+
+public class ESReporterConfiguration {
+
+ public static final boolean ENABLED = true;
+ public static final boolean DISABLED = !ENABLED;
+ public static final String DEFAULT_INDEX = "james-metrics";
+ public static final long DEFAULT_PERIOD_IN_SECOND = 60L;
+
+ public static ESReporterConfiguration disabled() {
+ return new ESReporterConfiguration(
+ Optional.empty(),
+ Optional.empty(),
+ DISABLED,
+ Optional.empty(),
+ Optional.empty());
+ }
+
+ public static ESReporterConfiguration enabled(String host, int port, Optional<String> index, Optional<Long> periodInSecond) {
+ return new ESReporterConfiguration(
+ Optional.of(host),
+ Optional.of(port),
+ ENABLED,
+ index,
+ periodInSecond);
+ }
+
+ private final Optional<String> host;
+ private final Optional<Integer> port;
+ private final boolean enabled;
+ private final Optional<String> index;
+ private final Optional<Long> periodInSecond;
+
+ public ESReporterConfiguration(Optional<String> host, Optional<Integer> port, boolean enabled, Optional<String> index, Optional<Long> periodInSecond) {
+ this.host = host;
+ this.port = port;
+ this.enabled = enabled;
+ this.index = index;
+ this.periodInSecond = periodInSecond;
+ }
+
+ public String getHostWithPort() {
+ Preconditions.checkState(host.isPresent());
+ Preconditions.checkState(port.isPresent());
+ return host.get() + ":" + port.get();
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public String getIndex() {
+ return index.orElse(DEFAULT_INDEX);
+ }
+
+ public long getPeriodInSecond() {
+ return periodInSecond.orElse(DEFAULT_PERIOD_IN_SECOND);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index deaaf91..aec7db9 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -294,6 +294,10 @@
======================================================================
-->
- <bean id="metricFactory" class="org.apache.james.metrics.dropwizard.DropWizardMetricFactory"/>
+ <bean id="metricFactory" class="org.apache.james.metrics.dropwizard.DropWizardMetricFactory">
+ <constructor-arg index="0" ref="metricRegistry"/>
+ </bean>
+
+ <bean id="metricRegistry" class="com.codahale.metrics.MetricRegistry"/>
</beans>
http://git-wip-us.apache.org/repos/asf/james-project/blob/ea114d7a/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 66fdedf..3569df4 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -65,6 +65,7 @@
<module>container/mailbox-adapter</module>
<module>container/metrics/metrics-api</module>
<module>container/metrics/metrics-dropwizard</module>
+ <module>container/metrics/metrics-es-reporter</module>
<module>container/spring</module>
<module>container/util</module>
<module>container/util-java8</module>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org