diff --git a/app/rpcApi.js b/app/rpcApi.js index 72d0e43..e65e795 100644 --- a/app/rpcApi.js +++ b/app/rpcApi.js @@ -69,6 +69,22 @@ function getNetworkInfo() { }); } +function getNetTotals() { + return new Promise(function(resolve, reject) { + client.cmd('getnettotals', function(err, result, resHeaders) { + if (err) { + console.log("Error as07uthf40ghew: " + err); + + reject(err); + + return; + } + + resolve(result); + }); + }); +} + function getMempoolInfo() { return new Promise(function(resolve, reject) { client.cmd('getmempoolinfo', function(err, result, resHeaders) { @@ -449,6 +465,7 @@ function getBlockData(rpcClient, blockHash, txLimit, txOffset) { module.exports = { getBlockchainInfo: getBlockchainInfo, getNetworkInfo: getNetworkInfo, + getNetTotals: getNetTotals, getMempoolInfo: getMempoolInfo, getBlockByHeight: getBlockByHeight, getBlocksByHeight: getBlocksByHeight, diff --git a/app/utils.js b/app/utils.js index e7ced35..39ab5dd 100644 --- a/app/utils.js +++ b/app/utils.js @@ -82,7 +82,21 @@ function getRandomString(length, chars) { result += mask[Math.floor(Math.random() * mask.length)]; } - return result; + return result; +} + +function formatBytes(bytesInt) { + var scales = [ {val:1000000000000000, name:"PB"}, {val:1000000000000, name:"TB"}, {val:1000000000, name:"GB"}, {val:1000000, name:"MB"}, {val:1000, name:"KB"} ]; + for (var i = 0; i < scales.length; i++) { + var item = scales[i]; + + var fraction = Math.floor(bytesInt / item.val); + if (fraction >= 1) { + return fraction.toLocaleString() + " " + item.name; + } + } + + return bytesInt + " B"; } @@ -92,5 +106,6 @@ module.exports = { hex2ascii: hex2ascii, getBlockReward: getBlockReward, splitArrayIntoChunks: splitArrayIntoChunks, - getRandomString: getRandomString + getRandomString: getRandomString, + formatBytes: formatBytes }; diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index 4fa76a5..3980ee9 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -63,8 +63,16 @@ router.get("/node-info", function(req, res) { rpcApi.getUptimeSeconds().then(function(uptimeSeconds) { res.locals.uptimeSeconds = uptimeSeconds; - res.render("node-info"); + rpcApi.getNetTotals().then(function(getnettotals) { + res.locals.getnettotals = getnettotals; + + res.render("node-info"); + + }).catch(function(err) { + res.locals.userMessage = "Unable to connect to Bitcoin Node at " + env.bitcoind.host + ":" + env.bitcoind.port; + res.render("node-info"); + }); }).catch(function(err) { res.locals.userMessage = "Unable to connect to Bitcoin Node at " + env.bitcoind.host + ":" + env.bitcoind.port; @@ -394,7 +402,7 @@ router.post("/terminal", function(req, res) { var params = req.body.cmd.split(" "); var cmd = params.shift(); var parsedParams = []; - + params.forEach(function(param, i) { if (!isNaN(param)) { parsedParams.push(parseInt(param)); diff --git a/views/node-info.pug b/views/node-info.pug index f92dbb3..07e2e9f 100644 --- a/views/node-info.pug +++ b/views/node-info.pug @@ -29,6 +29,10 @@ block content tr th(class="table-active properties-header") Protocol Version td(class="monospace") #{getnetworkinfo.protocolversion} + tr + th(class="table-active properties-header") Blockchain Size on Disk + td(class="monospace") #{getblockchaininfo.size_on_disk.toLocaleString()} + span (pruned: #{getblockchaininfo.pruned}) tr th(class="table-active properties-header") Connections td(class="monospace") #{getnetworkinfo.connections.toLocaleString()} @@ -65,9 +69,13 @@ block content td(class="monospace") #{startTimeAgo.format()} tr - th(class="table-active properties-header") Blockchain Size on Disk - td(class="monospace") #{getblockchaininfo.size_on_disk.toLocaleString()} - span (pruned: #{getblockchaininfo.pruned}) + th(class="table-active properties-header") Network Traffic + td(class="monospace") + span Total Download: #{utils.formatBytes(getnettotals.totalbytesrecv)} + span(class="text-muted") (avg #{utils.formatBytes(getnettotals.totalbytesrecv / uptimeSeconds)}/s) + br + span Total Upload: #{utils.formatBytes(getnettotals.totalbytessent)} + span(class="text-muted") (avg #{utils.formatBytes(getnettotals.totalbytessent / uptimeSeconds)}/s) tr th(class="table-active properties-header") Warnings