tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject tajo git commit: TAJO-1985: Add reporting metrics via JMX.
Date Fri, 27 Nov 2015 03:36:40 GMT
Repository: tajo
Updated Branches:
  refs/heads/master ee7279d23 -> 821fc172b


TAJO-1985: Add reporting metrics via JMX.

closes #879

Signed-off-by: Jinho Kim <jhkim@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/821fc172
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/821fc172
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/821fc172

Branch: refs/heads/master
Commit: 821fc172b93125170aed85aa6f9ff19a727999d4
Parents: ee7279d
Author: Yongjun Park <thehp.keybod@gmail.com>
Authored: Fri Nov 27 12:34:43 2015 +0900
Committer: Jinho Kim <jhkim@apache.org>
Committed: Fri Nov 27 12:35:20 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 +
 .../metrics/TestJMXTajoObjectNameFactory.java   | 64 ++++++++++++++++++
 .../util/metrics/TajoJMXObjectNameFactory.java  | 68 ++++++++++++++++++++
 .../tajo/util/metrics/TajoSystemMetrics.java    |  7 ++
 4 files changed, 141 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/821fc172/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index d2434d1..838ab65 100644
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,8 @@ Release 0.12.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1985: Supporting Metric report via JMX. (Yongjun Park via jinho)
+
     TAJO-1983: Improve memory usage of ExternalSortExec. (jinho)
 
     TAJO-1986: Rename the name 'option' to 'property' in TableMeta. (hyunsik)

http://git-wip-us.apache.org/repos/asf/tajo/blob/821fc172/tajo-core-tests/src/test/java/org/apache/tajo/util/metrics/TestJMXTajoObjectNameFactory.java
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/util/metrics/TestJMXTajoObjectNameFactory.java
b/tajo-core-tests/src/test/java/org/apache/tajo/util/metrics/TestJMXTajoObjectNameFactory.java
new file mode 100644
index 0000000..82e5ffb
--- /dev/null
+++ b/tajo-core-tests/src/test/java/org/apache/tajo/util/metrics/TestJMXTajoObjectNameFactory.java
@@ -0,0 +1,64 @@
+/**
+ * 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.tajo.util.metrics;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+public class TestJMXTajoObjectNameFactory {
+
+  TajoJMXObjectNameFactory jmxObjectNameFactory;
+
+  @Before
+  public void setUp() {
+    jmxObjectNameFactory = new TajoJMXObjectNameFactory();
+  }
+
+  @Test
+  public void testCreateNameWithSingleDepth() throws MalformedObjectNameException {
+    ObjectName objectName = jmxObjectNameFactory.createName("timers", "Tajo", "ACTIVE_NODES");
+    ObjectName expectedObjectName = new ObjectName("Tajo:name=ACTIVE_NODES");
+    assertEquals(objectName, expectedObjectName);
+  }
+
+  @Test
+  public void testCreateNameWith2Depth() throws MalformedObjectNameException {
+    ObjectName objectName = jmxObjectNameFactory.createName("timers", "Tajo", "MASTER-JVM.File");
+    ObjectName expectedObjectName = new ObjectName("Tajo:type=MASTER-JVM,name=File");
+    assertEquals(objectName, expectedObjectName);
+  }
+
+  @Test
+  public void testCreateNameWith3Depth() throws MalformedObjectNameException {
+    ObjectName objectName = jmxObjectNameFactory.createName("timers", "Tajo", "MASTER.CLUSTER.ACTIVE_NODES");
+    ObjectName expectedObjectName = new ObjectName("Tajo:type=MASTER,context=CLUSTER,name=ACTIVE_NODES");
+    assertEquals(objectName, expectedObjectName);
+  }
+
+  @Test
+  public void testCreateNameWith4Depth() throws MalformedObjectNameException {
+    ObjectName objectName = jmxObjectNameFactory.createName("timers", "Tajo", "MASTER-JVM.MEMORY.heap.used");
+    ObjectName expectedObjectName = new ObjectName("Tajo:type=MASTER-JVM,context=MEMORY,name=heap.used");
+    assertEquals(objectName, expectedObjectName);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/821fc172/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoJMXObjectNameFactory.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoJMXObjectNameFactory.java
b/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoJMXObjectNameFactory.java
new file mode 100644
index 0000000..d65ba98
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoJMXObjectNameFactory.java
@@ -0,0 +1,68 @@
+/**
+ * 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.tajo.util.metrics;
+
+import com.codahale.metrics.ObjectNameFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+public class TajoJMXObjectNameFactory implements ObjectNameFactory {
+  private static final Log LOG = LogFactory.getLog(TajoMetrics.class);
+  private static String[] jmxHierarchies = new String[] {"type", "context"};
+  private static String SEPARATOR_RGX = "\\.";
+
+  @Override
+  public ObjectName createName(String type, String domain, String name) {
+    try {
+      StringBuilder sb = new StringBuilder();
+      sb.append(domain).append(":");
+
+      String[] nameSplit = name.split(SEPARATOR_RGX, 3);
+      ObjectName objectName = null;
+      if (nameSplit.length == 1 ) {
+        objectName = new ObjectName(domain, "name", name);
+      } else {
+        for (int i = 0; i < nameSplit.length - 1 && i < jmxHierarchies.length;
i++) {
+          sb.append(jmxHierarchies[i]).append("=").append(nameSplit[i]).append(",");
+        }
+        sb.append("name=").append(nameSplit[nameSplit.length - 1]);
+        objectName = new ObjectName(sb.toString());
+      }
+
+      if (objectName.isPattern()) {
+        objectName = new ObjectName(domain, "name", ObjectName.quote(name));
+      }
+      return objectName;
+    } catch (MalformedObjectNameException e) {
+      try {
+        return new ObjectName(domain, "name", ObjectName.quote(name));
+      } catch (MalformedObjectNameException e1) {
+        if(LOG.isDebugEnabled()) {
+          LOG.warn("Unable to register for " + type + " " + name + " " + e1.getMessage(),
e1);
+        } else {
+          LOG.warn("Unable to register for " + type + " " + name + " " + e1.getMessage());
+        }
+        throw new RuntimeException(e1);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/821fc172/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoSystemMetrics.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoSystemMetrics.java b/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoSystemMetrics.java
index 8d02ddd..260d414 100644
--- a/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoSystemMetrics.java
+++ b/tajo-core/src/main/java/org/apache/tajo/util/metrics/TajoSystemMetrics.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.util.metrics;
 
+import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.jvm.FileDescriptorRatioGauge;
 import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
@@ -51,6 +52,8 @@ public class TajoSystemMetrics extends TajoMetrics {
 
   private String metricsPropertyFileName;
 
+  private JmxReporter jmxReporter;
+
   public TajoSystemMetrics(TajoConf tajoConf, Class clazz, String hostAndPort) {
     super(MetricsUtil.getGroupName(clazz));
 
@@ -96,6 +99,7 @@ public class TajoSystemMetrics extends TajoMetrics {
       propertyChangeChecker.interrupt();
     }
     stopAndClearReporter();
+    jmxReporter.close();
   }
 
   protected void stopAndClearReporter() {
@@ -120,6 +124,9 @@ public class TajoSystemMetrics extends TajoMetrics {
       metricRegistry.register(MetricRegistry.name(jvmMetricsName, "GC"), new GarbageCollectorMetricSet());
       metricRegistry.register(MetricRegistry.name(jvmMetricsName, "THREAD"), new ThreadStatesGaugeSet());
       metricRegistry.register(MetricRegistry.name(jvmMetricsName, "LOG"), new LogEventGaugeSet());
+      jmxReporter = JmxReporter.forRegistry(metricRegistry).inDomain("Tajo")
+              .createsObjectNamesWith(new TajoJMXObjectNameFactory()).build();
+      jmxReporter.start();
     }
     inited = true;
   }


Mime
View raw message