From c99f62fdadf14005e39db6a5b9aa8000d0a00446 Mon Sep 17 00:00:00 2001 From: Giovanni Matteo Fumarola Date: Tue, 5 Mar 2019 11:01:11 -0800 Subject: [PATCH] HDFS-14334. RBF: Use human readable format for long numbers in the Router UI. Contributed by Inigo Goiri. --- .../main/webapps/router/federationhealth.html | 16 ++++++++-------- .../src/main/webapps/static/dfs-dust.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.html b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.html index 0f089fe3c2e..c591698e4b6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.html +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.html @@ -177,10 +177,10 @@ - {numOfFiles} - {numOfBlocks} - {numOfBlocksMissing} - {numOfBlocksUnderReplicated} + {numOfFiles|fmt_human_number} + {numOfBlocks|fmt_human_number} + {numOfBlocksMissing|fmt_human_number} + {numOfBlocksUnderReplicated|fmt_human_number} {numOfActiveDatanodes} {numOfDeadDatanodes} {numOfDecommissioningDatanodes} @@ -244,10 +244,10 @@ - {numOfFiles} - {numOfBlocks} - {numOfBlocksMissing} - {numOfBlocksUnderReplicated} + {numOfFiles|fmt_human_number} + {numOfBlocks|fmt_human_number} + {numOfBlocksMissing|fmt_human_number} + {numOfBlocksUnderReplicated|fmt_human_number} {numOfActiveDatanodes} {numOfDeadDatanodes} {numOfDecommissioningDatanodes} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/dfs-dust.js b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/dfs-dust.js index 316a9947ca9..7772d72aef8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/dfs-dust.js +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/dfs-dust.js @@ -96,6 +96,22 @@ 'fmt_number': function (v) { return v.toLocaleString(); + }, + + 'fmt_human_number': function (v) { + var UNITS = ['', 'K', 'M']; + var prev = 0, i = 0; + while (Math.floor(v) > 0 && i < UNITS.length) { + prev = v; + v /= 1000; + i += 1; + } + + if (i > 0) { + v = prev; + i -= 1; + } + return Math.round(v * 100) / 100 + UNITS[i]; } }; $.extend(dust.filters, filters);