Browse Source

getnettotals info on /node-info page

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
0049484b29
  1. 17
      app/rpcApi.js
  2. 19
      app/utils.js
  3. 10
      routes/baseActionsRouter.js
  4. 14
      views/node-info.pug

17
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,

19
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
};

10
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;

14
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

Loading…
Cancel
Save