You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2016/07/13 21:23:00 UTC

oozie git commit: OOZIE-2507 Expose monitoring via JMX beans in Oozie (fdenes via rkanter)

Repository: oozie
Updated Branches:
  refs/heads/master aa6e2eb44 -> 1103a9631


OOZIE-2507 Expose monitoring via JMX beans in Oozie (fdenes via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/1103a963
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/1103a963
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/1103a963

Branch: refs/heads/master
Commit: 1103a9631b9669cb0ad06b9b9131928cc90829cb
Parents: aa6e2eb
Author: Robert Kanter <rk...@cloudera.com>
Authored: Wed Jul 13 14:21:32 2016 -0700
Committer: Robert Kanter <rk...@cloudera.com>
Committed: Wed Jul 13 14:22:44 2016 -0700

----------------------------------------------------------------------
 core/pom.xml                                    |  8 +++
 .../oozie/util/MetricsInstrumentation.java      | 13 ++++
 core/src/main/resources/oozie-default.xml       |  8 +++
 .../oozie/util/TestMetricsInstrumentation.java  | 65 ++++++++++++++++++++
 docs/src/site/twiki/AG_Install.twiki            | 12 ++++
 release-log.txt                                 |  1 +
 6 files changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/1103a963/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index b72ea7d..f19d83b 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -161,6 +161,14 @@
         </dependency>
 
         <dependency>
+            <groupId>com.sun</groupId>
+            <artifactId>tools</artifactId>
+            <version>${targetJavaVersion}</version>
+            <systemPath>${java.home}/../lib/tools.jar</systemPath>
+            <scope>system</scope>
+        </dependency>
+
+        <dependency>
             <groupId>commons-cli</groupId>
             <artifactId>commons-cli</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/oozie/blob/1103a963/core/src/main/java/org/apache/oozie/util/MetricsInstrumentation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/util/MetricsInstrumentation.java b/core/src/main/java/org/apache/oozie/util/MetricsInstrumentation.java
index 70c894f..9d69f74 100644
--- a/core/src/main/java/org/apache/oozie/util/MetricsInstrumentation.java
+++ b/core/src/main/java/org/apache/oozie/util/MetricsInstrumentation.java
@@ -23,6 +23,7 @@ import com.codahale.metrics.Counter;
 import com.codahale.metrics.ExponentiallyDecayingReservoir;
 import com.codahale.metrics.Gauge;
 import com.codahale.metrics.Histogram;
+import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricFilter;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.ganglia.GangliaReporter;
@@ -79,6 +80,7 @@ public class MetricsInstrumentation extends Instrumentation {
     public static final String EXTERNAL_MONITORING_ADDRESS = "oozie.external_monitoring.address";
     public static final String EXTERNAL_MONITORING_PREFIX = "oozie.external_monitoring.metricPrefix";
     public static final String EXTERNAL_MONITORING_INTERVAL = "oozie.external_monitoring.reporterIntervalSecs";
+    public static final String JMX_MONITORING_ENABLE = "oozie.jmx_monitoring.enable";
     public static final String GRAPHITE="graphite";
     public static final String GANGLIA="ganglia";
     private String metricsAddress;
@@ -88,8 +90,10 @@ public class MetricsInstrumentation extends Instrumentation {
     private int metricsPort;
     private GraphiteReporter graphiteReporter = null;
     private GangliaReporter gangliaReporter = null;
+    private JmxReporter jmxReporter = null;
     private long metricsReportIntervalSec;
     private boolean isExternalMonitoringEnabled;
+    private boolean isJMXMonitoringEnabled;
 
     private static final TimeUnit RATE_UNIT = TimeUnit.MILLISECONDS;
     private static final TimeUnit DURATION_UNIT = TimeUnit.MILLISECONDS;
@@ -191,6 +195,11 @@ public class MetricsInstrumentation extends Instrumentation {
         );
         gauges = new ConcurrentHashMap<String, Gauge>();
         histograms = new ConcurrentHashMap<String, Histogram>();
+        isJMXMonitoringEnabled = ConfigurationService.getBoolean(JMX_MONITORING_ENABLE);
+        if (isJMXMonitoringEnabled) {
+            jmxReporter  = JmxReporter.forRegistry(metricRegistry).build();
+            jmxReporter.start();
+        }
     }
 
     /**
@@ -214,6 +223,10 @@ public class MetricsInstrumentation extends Instrumentation {
                 gangliaReporter.stop();
             }
         }
+
+        if (jmxReporter != null) {
+            jmxReporter.stop();
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/oozie/blob/1103a963/core/src/main/resources/oozie-default.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/oozie-default.xml b/core/src/main/resources/oozie-default.xml
index 13984f9..4563c73 100644
--- a/core/src/main/resources/oozie-default.xml
+++ b/core/src/main/resources/oozie-default.xml
@@ -70,6 +70,14 @@
     </property>
 
     <property>
+        <name>oozie.jmx_monitoring.enable</name>
+        <value>false</value>
+        <description>
+            If the oozie functional metrics needs to be exposed via JMX interface, set it to true.
+        </description>
+    </property>
+
+    <property>
         <name>oozie.action.mapreduce.uber.jar.enable</name>
         <value>false</value>
         <description>

http://git-wip-us.apache.org/repos/asf/oozie/blob/1103a963/core/src/test/java/org/apache/oozie/util/TestMetricsInstrumentation.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/util/TestMetricsInstrumentation.java b/core/src/test/java/org/apache/oozie/util/TestMetricsInstrumentation.java
index 061c20a..a882c82 100644
--- a/core/src/test/java/org/apache/oozie/util/TestMetricsInstrumentation.java
+++ b/core/src/test/java/org/apache/oozie/util/TestMetricsInstrumentation.java
@@ -21,13 +21,25 @@ package org.apache.oozie.util;
 import com.codahale.metrics.Metric;
 import com.codahale.metrics.MetricFilter;
 import com.codahale.metrics.Timer;
+
+import java.io.File;
+import java.util.UUID;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import com.sun.tools.attach.VirtualMachine;
+import com.sun.tools.attach.VirtualMachineDescriptor;
+import com.sun.tools.attach.spi.AttachProvider;
 import org.apache.oozie.service.Services;
 import org.apache.oozie.test.XTestCase;
 
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
 // Most tests adpated from TestInstrumentation
 public class TestMetricsInstrumentation extends XTestCase {
     private static final long INTERVAL = 300;
@@ -42,10 +54,19 @@ public class TestMetricsInstrumentation extends XTestCase {
 
     @Override
     protected void setUp() throws Exception {
+        setSystemProperty("oozie.jmx_monitoring.enable", "true");
         super.setUp();
         new Services().init();
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        if (null != Services.get()) {
+            Services.get().destroy();
+        }
+        super.tearDown();
+    }
+
     public void testInstrumentationCounter() throws Exception {
         MetricsInstrumentation inst = new MetricsInstrumentation();
         assertEquals(0, inst.getMetricRegistry().getCounters().size());
@@ -199,4 +220,48 @@ public class TestMetricsInstrumentation extends XTestCase {
         } catch (UnsupportedOperationException uoe) {
         }
     }
+
+    public void testJMXInstrumentation() throws Exception {
+        final AttachProvider attachProvider = AttachProvider.providers().get(0);
+
+        VirtualMachineDescriptor descriptor = null;
+
+        //Setting the id of the VM unique, so we can find it.
+        String uniqueId = UUID.randomUUID().toString();
+        System.setProperty("process.unique.id", uniqueId);
+
+        //Finding our own VM by the id.
+        for(VirtualMachineDescriptor d : VirtualMachine.list()) {
+            String remoteUniqueId = VirtualMachine.attach(d).getSystemProperties().getProperty("process.unique.id");
+            if(remoteUniqueId != null && remoteUniqueId.equals(uniqueId))
+            {
+                descriptor = d;
+                break;
+            }
+        }
+
+        assertNotNull("Could not find own virtual machine", descriptor);
+
+        //Attaching JMX agent to our own VM
+        final VirtualMachine virtualMachine = attachProvider.attachVirtualMachine(descriptor);
+        String agent = virtualMachine.getSystemProperties().getProperty("java.home") +
+                File.separator + "lib" + File.separator + "management-agent.jar";
+        virtualMachine.loadAgent(agent);
+        final Object portObject = virtualMachine.getAgentProperties().
+                get("com.sun.management.jmxremote.localConnectorAddress");
+
+        final JMXServiceURL target = new JMXServiceURL(portObject + "");
+
+        JMXConnector jmxc = JMXConnectorFactory.connect(target);
+        MBeanServerConnection conn = jmxc.getMBeanServerConnection();
+
+        //Query a value through JMX from our own VM
+        Object value = null;
+        try {
+            value = conn.getAttribute(new ObjectName("metrics:name=jvm.memory.heap.committed"),"Value");
+        } catch (Exception e) {
+            fail("Could not fetch metric");
+        }
+        assertNotNull("JMX service error", value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/oozie/blob/1103a963/docs/src/site/twiki/AG_Install.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/AG_Install.twiki b/docs/src/site/twiki/AG_Install.twiki
index 2d36737..a03512c 100644
--- a/docs/src/site/twiki/AG_Install.twiki
+++ b/docs/src/site/twiki/AG_Install.twiki
@@ -818,6 +818,18 @@ properties should be specified in oozie-site.xml :
     </property>
     </verbatim>
 
+We can also publish the instrumentation metrics via JMX interface. For this the following property should be specified
+in oozie-site.xml :
+    <verbatim>
+    <property>
+         <name>oozie.jmx_monitoring.enable</name>
+         <value>false</value>
+         <description>
+             If the oozie functional metrics needs to be exposed via JMX interface, set it to true.
+         </description>
+     </property>>
+    </verbatim>
+
 #HA
 ---+++ High Availability (HA)
 

http://git-wip-us.apache.org/repos/asf/oozie/blob/1103a963/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 686378c..d1eb00e 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.3.0 release (trunk - unreleased)
 
+OOZIE-2507 Expose monitoring via JMX beans in Oozie (fdenes via rkanter)
 OOZIE-2581 Oozie should reset SecurityManager in finally block (satishsaley via rohini)
 OOZIE-2579 Bulk kill tests in TestBulkWorkflowXCommand might fail because of a race condition (pbacsko via rkanter)
 OOZIE-2587 Disable SchedulerService on certain tests (pbacsko via rkanter)