knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject knox git commit: KNOX-1618 - Add dropwizard metrics-jvm support
Date Fri, 07 Dec 2018 20:48:25 GMT
Repository: knox
Updated Branches:
  refs/heads/master 00dcbeab4 -> 8e004963b


KNOX-1618 - Add dropwizard metrics-jvm support

Signed-off-by: Kevin Risden <krisden@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/8e004963
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/8e004963
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/8e004963

Branch: refs/heads/master
Commit: 8e004963be83881547903da9de75a5eee72838ca
Parents: 00dcbea
Author: Kevin Risden <krisden@apache.org>
Authored: Wed Nov 21 09:28:57 2018 -0500
Committer: Kevin Risden <krisden@apache.org>
Committed: Fri Dec 7 15:47:55 2018 -0500

----------------------------------------------------------------------
 gateway-server/pom.xml                            |  4 ++++
 .../metrics/impl/DefaultMetricsService.java       | 18 ++++++++++++++++++
 .../metrics/impl/DefaultMetricsServiceTest.java   | 11 +++++++----
 pom.xml                                           |  6 ++++++
 4 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/8e004963/gateway-server/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml
index a447987..2cf7c53 100644
--- a/gateway-server/pom.xml
+++ b/gateway-server/pom.xml
@@ -261,6 +261,10 @@
         </dependency>
         <dependency>
             <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-jvm</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
             <artifactId>metrics-servlets</artifactId>
         </dependency>
 

http://git-wip-us.apache.org/repos/asf/knox/blob/8e004963/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
index 54f774b..26f08a1 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
@@ -18,6 +18,12 @@
 package org.apache.knox.gateway.services.metrics.impl;
 
 import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.jvm.BufferPoolMetricSet;
+import com.codahale.metrics.jvm.CachedThreadStatesGaugeSet;
+import com.codahale.metrics.jvm.ClassLoadingGaugeSet;
+import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
+import com.codahale.metrics.jvm.JvmAttributeGaugeSet;
+import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
 import org.apache.knox.gateway.GatewayMessages;
 import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.i18n.messages.MessagesFactory;
@@ -29,11 +35,13 @@ import org.apache.knox.gateway.services.metrics.MetricsReporter;
 import org.apache.knox.gateway.services.metrics.MetricsReporterException;
 import org.apache.knox.gateway.services.metrics.MetricsService;
 
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.ServiceLoader;
+import java.util.concurrent.TimeUnit;
 
 public class DefaultMetricsService implements MetricsService {
   private static GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
@@ -65,6 +73,7 @@ public class DefaultMetricsService implements MetricsService {
     if (config.isMetricsEnabled()) {
       loadInstrumentationProviders();
       loadAndInitReporters(config);
+      registerJvmMetricSets();
     }
   }
 
@@ -90,6 +99,15 @@ public class DefaultMetricsService implements MetricsService {
     }
   }
 
+  private void registerJvmMetricSets() {
+    metrics.registerAll(new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
+    metrics.registerAll(new CachedThreadStatesGaugeSet(5, TimeUnit.MINUTES));
+    metrics.registerAll(new ClassLoadingGaugeSet());
+    metrics.registerAll(new GarbageCollectorMetricSet());
+    metrics.registerAll(new JvmAttributeGaugeSet());
+    metrics.registerAll(new MemoryUsageGaugeSet());
+  }
+
   @Override
   public void start() throws ServiceLifecycleException {
     if (config.isMetricsEnabled()) {

http://git-wip-us.apache.org/repos/asf/knox/blob/8e004963/gateway-server/src/test/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsServiceTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsServiceTest.java
index 5f937a1..b541d54 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsServiceTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.knox.gateway.services.metrics.impl;
 
+import com.codahale.metrics.MetricFilter;
 import com.codahale.metrics.MetricRegistry;
 import org.apache.knox.gateway.config.impl.GatewayConfigImpl;
 import org.apache.knox.gateway.services.metrics.InstrumentationProvider;
@@ -43,6 +44,7 @@ public class DefaultMetricsServiceTest {
     MetricRegistry metricRegistry = (MetricRegistry) service.getContext().getProperty(DefaultMetricsService.METRICS_REGISTRY);
     Assert.assertNotNull(metricRegistry);
     service.stop();
+    service.getMetricRegistry().removeMatching(MetricFilter.ALL);
   }
 
   @Test
@@ -52,7 +54,7 @@ public class DefaultMetricsServiceTest {
     Map<Class<?>, InstrumentationProvider> map = service.getInstrumentationProviders();
     Assert.assertTrue(map.entrySet().isEmpty());
     Assert.assertNull(service.getInstrumented(HttpClientBuilder.class));
-
+    service.getMetricRegistry().removeMatching(MetricFilter.ALL);
   }
 
   @Test
@@ -64,11 +66,11 @@ public class DefaultMetricsServiceTest {
     Map<Class<?>, InstrumentationProvider> map = service.getInstrumentationProviders();
     Assert.assertTrue(map.entrySet().size() >= 2);
     Assert.assertNotNull(service.getInstrumented(HttpClientBuilder.class));
-
+    service.getMetricRegistry().removeMatching(MetricFilter.ALL);
   }
 
   @Test
-  public void reportersLoading() throws Exception {
+  public void reportersLoadingDisabled() throws Exception {
     DefaultMetricsService service = new DefaultMetricsService();
     GatewayConfigImpl config = new GatewayConfigImpl();
     config.set(GatewayConfigImpl.METRICS_ENABLED, "true");
@@ -79,6 +81,7 @@ public class DefaultMetricsServiceTest {
     for (MetricsReporter reporter : reporters) {
       Assert.assertFalse(reporter.isEnabled());
     }
+    service.getMetricRegistry().removeMatching(MetricFilter.ALL);
     config.set(GatewayConfigImpl.JMX_METRICS_REPORTING_ENABLED, "true");
     config.set(GatewayConfigImpl.GRAPHITE_METRICS_REPORTING_ENABLED, "true");
     service.init(config, null);
@@ -88,6 +91,6 @@ public class DefaultMetricsServiceTest {
     }
     service.start();
     service.stop();
+    service.getMetricRegistry().removeMatching(MetricFilter.ALL);
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/8e004963/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 6c9da47..1b8db03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1700,6 +1700,12 @@
                 <version>${metrics.version}</version>
             </dependency>
             <dependency>
+                <groupId>io.dropwizard.metrics</groupId>
+                <artifactId>metrics-jvm</artifactId>
+                <version>${metrics.version}</version>
+            </dependency>
+
+            <dependency>
                 <groupId>de.thetaphi</groupId>
                 <artifactId>forbiddenapis</artifactId>
                 <version>${forbiddenapis.version}</version>


Mime
View raw message