hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1077666 - in /hadoop/common/branches/branch-0.20-security-patches/src: hdfs/org/apache/hadoop/hdfs/server/namenode/ hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/ test/org/apache/hadoop/hdfs/server/namenode/metrics/
Date Fri, 04 Mar 2011 04:41:59 GMT
Author: omalley
Date: Fri Mar  4 04:41:58 2011
New Revision: 1077666

URL: http://svn.apache.org/viewvc?rev=1077666&view=rev
Log:
commit 5be6b17cc63ed16aaa0376e72f35f683078e0a6d
Author: Luke Lu <llu@yahoo-inc.com>
Date:   Tue Sep 7 17:57:10 2010 -0700

     Fix FSNamesystemMetrics MBean registration
    
    which failed at first try, by removing a circular dependency
    in metrics initialization.

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
    hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeInstrumentation.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1077666&r1=1077665&r2=1077666&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
Fri Mar  4 04:41:58 2011
@@ -99,6 +99,10 @@ import org.apache.hadoop.hdfs.server.pro
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.ipc.Server;
+import org.apache.hadoop.metrics2.MetricsBuilder;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 import org.apache.hadoop.metrics2.util.MBeans;
 import org.apache.hadoop.net.CachedDNSToSwitchMapping;
 import org.apache.hadoop.net.DNSToSwitchMapping;
@@ -130,7 +134,7 @@ import org.mortbay.util.ajax.JSON;
  * 5)  LRU cache of updated-heartbeat machines
  ***************************************************/
 public class FSNamesystem implements FSConstants, FSNamesystemMBean,
-    NameNodeMXBean {
+    NameNodeMXBean, MetricsSource {
   public static final Log LOG = LogFactory.getLog(FSNamesystem.class);
   public static final String AUDIT_FORMAT =
     "ugi=%s\t" +  // ugi
@@ -412,6 +416,7 @@ public class FSNamesystem implements FSC
     }
     
     registerMXBean();
+    registerWith(DefaultMetricsSystem.INSTANCE);
   }
 
   public static Collection<File> getNamespaceDirs(Configuration conf) {
@@ -5291,4 +5296,36 @@ public class FSNamesystem implements FSC
   private long getDfsUsed(DatanodeDescriptor alivenode) {
     return alivenode.getDfsUsed();
   }
+
+  private static int roundBytesToGBytes(long bytes) {
+    return Math.round(((float)bytes/(1024 * 1024 * 1024)));
+  }
+
+  @Override
+  public void getMetrics(MetricsBuilder builder, boolean all) {
+    builder.addRecord("FSNamesystem").setContext("dfs")
+      .addGauge("FilesTotal", "", getFilesTotal())
+      .addGauge("BlocksTotal", "", getBlocksTotal())
+      .addGauge("CapacityTotalGB", "",
+                roundBytesToGBytes(getCapacityTotal()))
+      .addGauge("CapacityUsedGB", "",
+                roundBytesToGBytes(getCapacityUsed()))
+      .addGauge("CapacityRemainingGB", "",
+                roundBytesToGBytes(getCapacityRemaining()))
+      .addGauge("TotalLoad", "", getTotalLoad())
+      .addGauge("CorruptBlocks", "", getCorruptReplicaBlocks())
+      .addGauge("ExcessBlocks", "", getExcessBlocks())
+      .addGauge("PendingDeletionBlocks", "", getPendingDeletionBlocks())
+      .addGauge("PendingReplicationBlocks", "", getPendingReplicationBlocks())
+      .addGauge("UnderReplicatedBlocks", "", getUnderReplicatedBlocks())
+      .addGauge("ScheduledReplicationBlocks", "",
+                getScheduledReplicationBlocks())
+      .addGauge("MissingBlocks", "", getMissingBlocksCount())
+      .addGauge("BlockCapacity", "", getBlockCapacity());
+  }
+
+  private void registerWith(MetricsSystem ms) {
+    ms.register("FSNamesystemMetrics", "FSNamesystem metrics", this);
+  }
+
 }

Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeInstrumentation.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeInstrumentation.java?rev=1077666&r1=1077665&r2=1077666&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeInstrumentation.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeInstrumentation.java
Fri Mar  4 04:41:58 2011
@@ -21,7 +21,6 @@ package org.apache.hadoop.hdfs.server.na
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.Log;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
 import org.apache.hadoop.metrics2.MetricsBuilder;
 import org.apache.hadoop.metrics2.MetricsSource;
 import org.apache.hadoop.metrics2.MetricsSystem;
@@ -35,7 +34,6 @@ import org.apache.hadoop.metrics2.source
 public class NameNodeInstrumentation implements MetricsSource {
   static final Log LOG = LogFactory.getLog(NameNodeInstrumentation.class);
 
-  static final String FSNAMESYSTEM_RECORD_NAME = "FSNamesystem";
   final String sessionId;
   final MetricsRegistry registry = new MetricsRegistry("namenode");
   final MetricMutableCounterInt numFilesCreated =
@@ -70,11 +68,8 @@ public class NameNodeInstrumentation imp
   final MetricMutableCounterInt numFilesInGetListingOps =
       registry.newCounter("FilesInGetListingOps", "", 0);
 
-  final MetricsSource fsNamesystemMetrics;
-
   NameNodeInstrumentation(Configuration conf) {
     sessionId = conf.get("session.id");
-    fsNamesystemMetrics = new FSNamesystemMetrics();
     JvmMetricsSource.create("NameNode", sessionId);
     registry.setContext("dfs").tag("sessionId", "", sessionId);
   }
@@ -91,21 +86,14 @@ public class NameNodeInstrumentation imp
    */
   public static NameNodeInstrumentation create(Configuration conf,
                                                MetricsSystem ms) {
-    NameNodeInstrumentation v2 = new NameNodeInstrumentation(conf);
-    ms.register("FSNamesystemState", "FS name system state",
-                v2.fsNamesystemMetrics());
-    return ms.register("NameNode", "NameNode metrics", v2);
-  }
-
-  public MetricsSource fsNamesystemMetrics() {
-    return fsNamesystemMetrics;
+    return ms.register("NameNode", "NameNode metrics",
+                       new NameNodeInstrumentation(conf));
   }
 
   public void shutdown() {
     // metrics system shutdown would suffice
   }
 
-
   public final void incrNumGetBlockLocations() {
     numGetBlockLocations.incr();
   }
@@ -194,45 +182,4 @@ public class NameNodeInstrumentation imp
     registry.snapshot(builder.addRecord(registry.name()), all);
   }
 
-  private static int roundBytesToGBytes(long bytes) {
-    return Math.round(((float)bytes/(1024 * 1024 * 1024)));
-  }
-
-  private class FSNamesystemMetrics implements MetricsSource {
-
-    public void getMetrics(MetricsBuilder builder, boolean all) {
-      // Since fsnamesystem metrics are poll based, we just put them here
-      // to avoid an extra copy per metric.
-      FSNamesystem fsNamesystem = FSNamesystem.getFSNamesystem();
-      if (fsNamesystem == null) {
-        LOG.debug("FSNamesystem not ready yet!");
-        return;
-      }
-      builder.addRecord(FSNAMESYSTEM_RECORD_NAME).setContext("dfs")
-        .tag("sessionId", "", sessionId)
-        .addGauge("FilesTotal", "", fsNamesystem.getFilesTotal())
-        .addGauge("BlocksTotal", "", fsNamesystem.getBlocksTotal())
-        .addGauge("CapacityTotalGB", "",
-                  roundBytesToGBytes(fsNamesystem.getCapacityTotal()))
-        .addGauge("CapacityUsedGB", "",
-                  roundBytesToGBytes(fsNamesystem.getCapacityUsed()))
-        .addGauge("CapacityRemainingGB", "",
-                  roundBytesToGBytes(fsNamesystem.getCapacityRemaining()))
-        .addGauge("TotalLoad", "", fsNamesystem.getTotalLoad())
-        .addGauge("CorruptBlocks", "", fsNamesystem.getCorruptReplicaBlocks())
-        .addGauge("ExcessBlocks", "", fsNamesystem.getExcessBlocks())
-        .addGauge("PendingDeletionBlocks", "",
-                  fsNamesystem.getPendingDeletionBlocks())
-        .addGauge("PendingReplicationBlocks", "",
-                  fsNamesystem.getPendingReplicationBlocks())
-        .addGauge("UnderReplicatedBlocks", "",
-                  fsNamesystem.getUnderReplicatedBlocks())
-        .addGauge("ScheduledReplicationBlocks", "",
-                  fsNamesystem.getScheduledReplicationBlocks())
-        .addGauge("MissingBlocks", "", fsNamesystem.getMissingBlocksCount())
-        .addGauge("BlockCapacity", "", fsNamesystem.getBlockCapacity());
-    }
-
-  }
-
 }

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java?rev=1077666&r1=1077665&r2=1077666&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
Fri Mar  4 04:41:58 2011
@@ -74,7 +74,7 @@ public class TestNameNodeMetrics extends
     namesystem = cluster.getNameNode().getNamesystem();
     fs = (DistributedFileSystem) cluster.getFileSystem();
     nnMetrics = NameNode.getNameNodeMetrics();
-    fsnMetrics = nnMetrics.fsNamesystemMetrics();
+    fsnMetrics = namesystem;
   }
   
   @Override



Mime
View raw message