Skip to content

Commit d746e2c

Browse files
tomscutjojochuang
authored andcommitted
HDFS-16337. Show start time of Datanode on Web (#3682)
Reviewed-by: Inigo Goiri <inigoiri@apache.org> (cherry picked from commit 0ed817b)
1 parent cbb3ba1 commit d746e2c

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import static org.apache.hadoop.hdfs.protocol.datatransfer.BlockConstructionStage.PIPELINE_SETUP_CREATE;
5151
import static org.apache.hadoop.hdfs.protocol.datatransfer.BlockConstructionStage.PIPELINE_SETUP_STREAMING_RECOVERY;
5252
import static org.apache.hadoop.util.ExitUtil.terminate;
53+
import static org.apache.hadoop.util.Time.now;
5354

5455
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
5556
import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ReconfigurationProtocolService;
@@ -415,6 +416,8 @@ private static Tracer createTracer(Configuration conf) {
415416

416417
private ScheduledThreadPoolExecutor metricsLoggerTimer;
417418

419+
private final long startTime = now();
420+
418421
/**
419422
* Creates a dummy DataNode for testing purpose.
420423
*/
@@ -3109,6 +3112,11 @@ public String getHttpPort(){
31093112
return this.getConf().get("dfs.datanode.info.port");
31103113
}
31113114

3115+
@Override // DataNodeMXBean
3116+
public long getDNStartedTimeInMillis() {
3117+
return this.startTime;
3118+
}
3119+
31123120
public String getRevision() {
31133121
return VersionInfo.getRevision();
31143122
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,11 @@ public interface DataNodeMXBean {
157157
* @return true, if security is enabled.
158158
*/
159159
boolean isSecurityEnabled();
160+
161+
/**
162+
* Get the start time of the DataNode.
163+
*
164+
* @return Start time of the DataNode.
165+
*/
166+
long getDNStartedTimeInMillis();
160167
}

hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/datanode.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<div class="page-header"><h1>DataNode on <small>{HostName}:{DataPort}</small></h1></div>
7272
<table class="table table-bordered table-striped">
7373
<tr><th>Cluster ID:</th><td>{ClusterId}</td></tr>
74+
<tr><th>Started:</th><td>{DNStartedTimeInMillis|date_tostring}</td></tr>
7475
<tr><th>Version:</th><td>{Version}</td></tr>
7576
</table>
7677
{/dn}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public void testDataNodeMXBean() throws Exception {
7575
// get attribute "Version"
7676
String version = (String)mbs.getAttribute(mxbeanName, "Version");
7777
Assert.assertEquals(datanode.getVersion(),version);
78+
// get attribute "DNStartedTimeInMillis"
79+
long startTime = (long) mbs.getAttribute(mxbeanName, "DNStartedTimeInMillis");
80+
Assert.assertEquals(datanode.getDNStartedTimeInMillis(), startTime);
7881
// get attribute "SotfwareVersion"
7982
String softwareVersion =
8083
(String)mbs.getAttribute(mxbeanName, "SoftwareVersion");

0 commit comments

Comments
 (0)