added node latency
This commit is contained in:
parent
76de55f2e5
commit
6c17d0ee9c
5
app.js
5
app.js
@ -20,6 +20,7 @@ api = new Primus(server, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
api.use('emit', require('primus-emit'));
|
api.use('emit', require('primus-emit'));
|
||||||
|
api.use('spark-latency', require('primus-spark-latency'));
|
||||||
|
|
||||||
var client = new Primus(server, {
|
var client = new Primus(server, {
|
||||||
transformer: 'websockets',
|
transformer: 'websockets',
|
||||||
@ -30,12 +31,14 @@ var client = new Primus(server, {
|
|||||||
client.use('emit', require('primus-emit'));
|
client.use('emit', require('primus-emit'));
|
||||||
|
|
||||||
api.on('connection', function(spark) {
|
api.on('connection', function(spark) {
|
||||||
|
console.log('Latency: ', spark.latency);
|
||||||
console.log(spark.id);
|
console.log(spark.id);
|
||||||
console.log(spark.address);
|
console.log(spark.address);
|
||||||
console.log(spark.query);
|
console.log(spark.query);
|
||||||
|
|
||||||
spark.on('hello', function(data)
|
spark.on('hello', function(data)
|
||||||
{
|
{
|
||||||
|
console.log('Latency: ', spark.latency);
|
||||||
console.log('got hello data from ', spark.id);
|
console.log('got hello data from ', spark.id);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
@ -53,11 +56,13 @@ api.on('connection', function(spark) {
|
|||||||
|
|
||||||
spark.on('update', function(data)
|
spark.on('update', function(data)
|
||||||
{
|
{
|
||||||
|
console.log('Latency: ', spark.latency);
|
||||||
console.log('got update from ' + spark.id);
|
console.log('got update from ' + spark.id);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
if(typeof data.id !== 'undefined' && typeof data.stats !== 'undefined')
|
if(typeof data.id !== 'undefined' && typeof data.stats !== 'undefined')
|
||||||
{
|
{
|
||||||
|
data.stats.latency = spark.latency;
|
||||||
var stats = Nodes.update(data.id, data.stats);
|
var stats = Nodes.update(data.id, data.stats);
|
||||||
|
|
||||||
client.write({action: 'update', data: stats});
|
client.write({action: 'update', data: stats});
|
||||||
|
@ -21,6 +21,7 @@ var Node = function Node(data)
|
|||||||
},
|
},
|
||||||
blocktimeAvg: 0,
|
blocktimeAvg: 0,
|
||||||
difficulty: [],
|
difficulty: [],
|
||||||
|
latency: 0,
|
||||||
uptime: 0,
|
uptime: 0,
|
||||||
lastUpdate: 0
|
lastUpdate: 0
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
"lodash": "^3.2.0",
|
"lodash": "^3.2.0",
|
||||||
"primus": "^2.4.12",
|
"primus": "^2.4.12",
|
||||||
"primus-emit": "^0.1.2",
|
"primus-emit": "^0.1.2",
|
||||||
|
"primus-spark-latency": "^0.1.1",
|
||||||
"serve-favicon": "~2.1.3",
|
"serve-favicon": "~2.1.3",
|
||||||
"ws": "^0.7.1"
|
"ws": "^0.7.1"
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,14 @@ angular.module('netStatsApp.filters', [])
|
|||||||
return (typeof gas !== 'undefined' ? parseInt(gas) : '?');
|
return (typeof gas !== 'undefined' ? parseInt(gas) : '?');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.filter('latencyFilter', function() {
|
||||||
|
return function(stats) {
|
||||||
|
if(stats.active === false)
|
||||||
|
return 'offline';
|
||||||
|
else
|
||||||
|
return stats.latency + ' ms';
|
||||||
|
}
|
||||||
|
})
|
||||||
.filter('hashFilter', function() {
|
.filter('hashFilter', function() {
|
||||||
return function(hash) {
|
return function(hash) {
|
||||||
return hash.substr(0, 6) + '...' + hash.substr(58, 6);
|
return hash.substr(0, 6) + '...' + hash.substr(58, 6);
|
||||||
@ -79,7 +87,7 @@ angular.module('netStatsApp.filters', [])
|
|||||||
var diff = time - timestamp;
|
var diff = time - timestamp;
|
||||||
|
|
||||||
if(diff < 60)
|
if(diff < 60)
|
||||||
return Math.round(diff) + ' s';
|
return Math.round(diff) + ' s ago';
|
||||||
|
|
||||||
return moment.duration(Math.round(diff), 's').humanize() + ' ago';
|
return moment.duration(Math.round(diff), 's').humanize() + ' ago';
|
||||||
};
|
};
|
||||||
|
@ -77,6 +77,8 @@ block content
|
|||||||
i.icon-node(data-toggle="tooltip", data-placement="top", title="Node")
|
i.icon-node(data-toggle="tooltip", data-placement="top", title="Node")
|
||||||
th
|
th
|
||||||
i.icon-laptop(data-toggle="tooltip", data-placement="top", title="Node type")
|
i.icon-laptop(data-toggle="tooltip", data-placement="top", title="Node type")
|
||||||
|
th
|
||||||
|
i.icon-gas(data-toggle="tooltip", data-placement="top", title="Node latency")
|
||||||
th
|
th
|
||||||
i.icon-mining(data-toggle="tooltip", data-placement="top", title="Is mining")
|
i.icon-mining(data-toggle="tooltip", data-placement="top", title="Is mining")
|
||||||
th
|
th
|
||||||
@ -100,8 +102,9 @@ block content
|
|||||||
td
|
td
|
||||||
div.small(ng-bind-html="node.info.node | nodeVersion")
|
div.small(ng-bind-html="node.info.node | nodeVersion")
|
||||||
//- div.small {{node.info.os}}, {{node.info.os_v}}
|
//- div.small {{node.info.os}}, {{node.info.os_v}}
|
||||||
|
td.small(class="{{ node.stats | mainClass : bestBlock }}") {{node.stats | latencyFilter}}
|
||||||
td(class="{{ node.stats.mining | miningClass }}")
|
td(class="{{ node.stats.mining | miningClass }}")
|
||||||
i(class="{{ node.stats.mining | miningIconClass }}")
|
i.small(class="{{ node.stats.mining | miningIconClass }}")
|
||||||
td(class="{{ node.stats.peers | peerClass }}", style="padding-left: 18px;") {{node.stats.peers}}
|
td(class="{{ node.stats.peers | peerClass }}", style="padding-left: 18px;") {{node.stats.peers}}
|
||||||
td(style="padding-left: 18px;") {{node.stats.pending}}
|
td(style="padding-left: 18px;") {{node.stats.pending}}
|
||||||
td(class="{{ node.stats.block.number | blockClass : bestBlock }}") {{'#' + node.stats.block.number}}
|
td(class="{{ node.stats.block.number | blockClass : bestBlock }}") {{'#' + node.stats.block.number}}
|
||||||
|
Loading…
Reference in New Issue
Block a user