From 0db41dd2dea6156dd0e838404278a5a6e690ce69 Mon Sep 17 00:00:00 2001
From: Eli Collins <eli@cloudera.com>
Date: Tue, 12 Jan 2010 14:45:13 -0800
Subject: [PATCH] HDFS-412: Hadoop JMX usage makes Nagios monitoring impossible (HADOOP-4482)

---
 .../hadoop/hdfs/server/datanode/DataNode.java      |    2 +-
 .../datanode/metrics/DataNodeActivityMBean.java    |   16 +++++++++-------
 .../server/datanode/metrics/DataNodeMetrics.java   |    4 ++--
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
index ca1be5b..95a4462 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
@@ -382,7 +382,7 @@ public class DataNode extends Configured
     this.infoServer.start();
     // adjust info port
     this.dnRegistration.setInfoPort(this.infoServer.getPort());
-    myMetrics = new DataNodeMetrics(conf, dnRegistration.getStorageID());
+    myMetrics = new DataNodeMetrics(conf, dnRegistration.getName());
     
     // set service-level authorization security policy
     if (conf.getBoolean(
diff --git a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeActivityMBean.java b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeActivityMBean.java
index b555c90..db4b8b6 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeActivityMBean.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeActivityMBean.java
@@ -28,7 +28,7 @@ import org.apache.hadoop.metrics.util.MetricsRegistry;
  * 
  * This is the JMX MBean for reporting the DataNode Activity.
  * The MBean is register using the name
- *        "hadoop:service=DataNode,name=DataNodeActivity-<storageid>"
+ *        "hadoop:service=DataNode,name=DataNodeActivity-<hostname>-<portNumber>"
  * 
  * Many of the activity metrics are sampled and averaged on an interval 
  * which can be specified in the metrics config file.
@@ -57,15 +57,17 @@ public class DataNodeActivityMBean extends MetricsDynamicMBeanBase {
   final private ObjectName mbeanName;
   private Random rand = new Random(); 
 
-  public DataNodeActivityMBean(final MetricsRegistry mr, final String storageId) {
+  public DataNodeActivityMBean(final MetricsRegistry mr,
+      final String datanodeName) {
     super(mr, "Activity statistics at the DataNode");
-    String storageName;
-    if (storageId.equals("")) {// Temp fix for the uninitialized storage
-      storageName = "UndefinedStorageId" + rand.nextInt();
+    String name;
+    if (datanodeName.equals("")) {// Temp fix for the uninitialized name
+      name = "UndefinedDataNodeName" + rand.nextInt();
     } else {
-      storageName = storageId;
+      name = datanodeName.replace(":", "-");
     }
-    mbeanName = MBeanUtil.registerMBean("DataNode", "DataNodeActivity-" + storageName, this);
+    mbeanName = MBeanUtil.registerMBean("DataNode",
+	"DataNodeActivity-" + name, this);
   }
   
 
diff --git a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeMetrics.java b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeMetrics.java
index d60ae64..eaffef4 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeMetrics.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeMetrics.java
@@ -92,14 +92,14 @@ public class DataNodeMetrics implements Updater {
                     new MetricsTimeVaryingRate("blockReports", registry);
 
     
-  public DataNodeMetrics(Configuration conf, String storageId) {
+  public DataNodeMetrics(Configuration conf, String datanodeName) {
     String sessionId = conf.get("session.id"); 
     // Initiate reporting of Java VM metrics
     JvmMetrics.init("DataNode", sessionId);
     
 
     // Now the MBean for the data node
-    datanodeActivityMBean = new DataNodeActivityMBean(registry, storageId);
+    datanodeActivityMBean = new DataNodeActivityMBean(registry, datanodeName);
     
     // Create record for DataNode metrics
     MetricsContext context = MetricsUtil.getContext("dfs");
-- 
1.6.0.4

