JAMES-1950 Adding metric collection for JVM data

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d0ba1776
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d0ba1776
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d0ba1776

Branch: refs/heads/master
Commit: d0ba1776d00606656ce04f49be2418af7c287090
Parents: 785aaef
Author: benwa <btell...@linagora.com>
Authored: Wed Mar 22 23:08:36 2017 +0700
Committer: benwa <btell...@linagora.com>
Committed: Fri Mar 24 08:40:29 2017 +0700

----------------------------------------------------------------------
 metrics/metrics-dropwizard/pom.xml              |  4 ++
 .../dropwizard/DropWizardJVMMetrics.java        | 47 ++++++++++++++++++++
 metrics/pom.xml                                 |  7 ++-
 .../modules/server/DropWizardMetricsModule.java |  7 ++-
 server/pom.xml                                  |  7 ++-
 5 files changed, 69 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d0ba1776/metrics/metrics-dropwizard/pom.xml
----------------------------------------------------------------------
diff --git a/metrics/metrics-dropwizard/pom.xml 
b/metrics/metrics-dropwizard/pom.xml
index 7b1dec8..10131ec 100644
--- a/metrics/metrics-dropwizard/pom.xml
+++ b/metrics/metrics-dropwizard/pom.xml
@@ -45,6 +45,10 @@
             <artifactId>metrics-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-jvm</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0ba1776/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardJVMMetrics.java
----------------------------------------------------------------------
diff --git 
a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardJVMMetrics.java
 
b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardJVMMetrics.java
new file mode 100644
index 0000000..2312081
--- /dev/null
+++ 
b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardJVMMetrics.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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 javax.inject.Inject;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.jvm.ClassLoadingGaugeSet;
+import com.codahale.metrics.jvm.FileDescriptorRatioGauge;
+import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
+import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
+import com.codahale.metrics.jvm.ThreadStatesGaugeSet;
+
+public class DropWizardJVMMetrics {
+
+    private final MetricRegistry metricRegistry;
+
+    @Inject
+    public DropWizardJVMMetrics(MetricRegistry metricRegistry) {
+        this.metricRegistry = metricRegistry;
+    }
+
+    public void start() {
+        metricRegistry.register("jvm.file.descriptor", new 
FileDescriptorRatioGauge());
+        metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet());
+        metricRegistry.register("jvm.threads", new ThreadStatesGaugeSet());
+        metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet());
+        metricRegistry.register("jvm.class.loading", new 
ClassLoadingGaugeSet());
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0ba1776/metrics/pom.xml
----------------------------------------------------------------------
diff --git a/metrics/pom.xml b/metrics/pom.xml
index 1fad2ef..b668ed9 100644
--- a/metrics/pom.xml
+++ b/metrics/pom.xml
@@ -45,7 +45,7 @@
         <guava.version>18.0</guava.version>
         <javax.inject.version>1</javax.inject.version>
         <junit.version>4.11</junit.version>
-        <metrics.version>3.1.0</metrics.version>
+        <metrics.version>3.2.1</metrics.version>
         <testcontainers-version>1.1.7</testcontainers-version>
     </properties>
 
@@ -82,6 +82,11 @@
                 <version>${metrics.version}</version>
             </dependency>
             <dependency>
+                <groupId>io.dropwizard.metrics</groupId>
+                <artifactId>metrics-jvm</artifactId>
+                <version>${metrics.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>javax.inject</groupId>
                 <artifactId>javax.inject</artifactId>
                   <version>${javax.inject.version}</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0ba1776/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
index 5c53876..2e5d3c9 100644
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
+++ 
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
@@ -25,6 +25,7 @@ import 
org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.dropwizard.DropWizardJVMMetrics;
 import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
 import org.apache.james.utils.ConfigurationPerformer;
 
@@ -43,6 +44,7 @@ public class DropWizardMetricsModule extends AbstractModule {
     protected void configure() {
         bind(MetricRegistry.class).in(Scopes.SINGLETON);
         bind(DropWizardMetricFactory.class).in(Scopes.SINGLETON);
+        bind(DropWizardJVMMetrics.class).in(Scopes.SINGLETON);
         bind(MetricFactory.class).to(DropWizardMetricFactory.class);
 
         Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(DropWizardConfigurationPerformer.class);
@@ -76,15 +78,18 @@ public class DropWizardMetricsModule extends AbstractModule 
{
 
     public static class DropWizardInitializer implements Configurable {
         private final DropWizardMetricFactory dropWizardMetricFactory;
+        private final DropWizardJVMMetrics dropWizardJVMMetrics;
 
         @Inject
-        public DropWizardInitializer(DropWizardMetricFactory 
dropWizardMetricFactory) {
+        public DropWizardInitializer(DropWizardMetricFactory 
dropWizardMetricFactory, DropWizardJVMMetrics dropWizardJVMMetrics) {
             this.dropWizardMetricFactory = dropWizardMetricFactory;
+            this.dropWizardJVMMetrics = dropWizardJVMMetrics;
         }
 
         @Override
         public void configure(HierarchicalConfiguration config) throws 
ConfigurationException {
             dropWizardMetricFactory.start();
+            dropWizardJVMMetrics.start();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0ba1776/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 84f4401..d7791ed 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -188,7 +188,7 @@
         <assertj-3.version>3.3.0</assertj-3.version>
         <testcontainers-version>1.1.7</testcontainers-version>
         <guavate.version>1.0.0</guavate.version>
-        <metrics.version>3.1.0</metrics.version>
+        <metrics.version>3.2.1</metrics.version>
         <joda.version>2.9.4</joda.version>
     </properties>
 
@@ -1375,6 +1375,11 @@
                 <artifactId>metrics-core</artifactId>
                 <version>${metrics.version}</version>
             </dependency>
+            <dependency>
+                <groupId>io.dropwizard.metrics</groupId>
+                <artifactId>metrics-jvm</artifactId>
+                <version>${metrics.version}</version>
+            </dependency>
             <!-- This needed to let the bundle plugin to generate the right 
import statement -->
             <dependency>
                 <groupId>org.apache.geronimo.specs</groupId>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to