Explorar el Código

HDFS-16337. Show start time of Datanode on Web (#3682)

Reviewed-by: Inigo Goiri <inigoiri@apache.org>
(cherry picked from commit 0ed817babbcaa0560c11e2065cff3fff0bf328c5)
(cherry picked from commit d746e2cdd80335c86526b293f284187ce07758c4)
litao hace 3 años
padre
commit
2b0339cd34

+ 8 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java

@@ -47,6 +47,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_MAX_NUM_BLOCKS_TO_LOG_KEY
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_METRICS_LOGGER_PERIOD_SECONDS_DEFAULT;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_METRICS_LOGGER_PERIOD_SECONDS_KEY;
 import static org.apache.hadoop.util.ExitUtil.terminate;
+import static org.apache.hadoop.util.Time.now;
 
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ReconfigurationProtocolService;
@@ -412,6 +413,8 @@ public class DataNode extends ReconfigurableBase
 
   private ScheduledThreadPoolExecutor metricsLoggerTimer;
 
+  private final long startTime = now();
+
   /**
    * Creates a dummy DataNode for testing purpose.
    */
@@ -3092,6 +3095,11 @@ public class DataNode extends ReconfigurableBase
     return this.getConf().get("dfs.datanode.info.port");
   }
 
+  @Override // DataNodeMXBean
+  public long getDNStartedTimeInMillis() {
+    return this.startTime;
+  }
+
   public String getRevision() {
     return VersionInfo.getRevision();
   }

+ 7 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java

@@ -153,4 +153,11 @@ public interface DataNodeMXBean {
    * @return true, if security is enabled.
    */
   boolean isSecurityEnabled();
+
+  /**
+   * Get the start time of the DataNode.
+   *
+   * @return Start time of the DataNode.
+   */
+  long getDNStartedTimeInMillis();
 }

+ 1 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/datanode.html

@@ -71,6 +71,7 @@
 <div class="page-header"><h1>DataNode on <small>{HostName}:{DataPort}</small></h1></div>
 <table class="table table-bordered table-striped">
   <tr><th>Cluster ID:</th><td>{ClusterId}</td></tr>
+  <tr><th>Started:</th><td>{DNStartedTimeInMillis|date_tostring}</td></tr>
   <tr><th>Version:</th><td>{Version}</td></tr>
 </table>
 {/dn}

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java

@@ -75,6 +75,9 @@ public class TestDataNodeMXBean extends SaslDataTransferTestCase {
       // get attribute "Version"
       String version = (String)mbs.getAttribute(mxbeanName, "Version");
       Assert.assertEquals(datanode.getVersion(),version);
+      // get attribute "DNStartedTimeInMillis"
+      long startTime = (long) mbs.getAttribute(mxbeanName, "DNStartedTimeInMillis");
+      Assert.assertEquals(datanode.getDNStartedTimeInMillis(), startTime);
       // get attribute "SotfwareVersion"
       String softwareVersion =
           (String)mbs.getAttribute(mxbeanName, "SoftwareVersion");