added latency update
This commit is contained in:
parent
9487a06dbd
commit
ec14cc4d67
17
app.js
17
app.js
@ -79,6 +79,23 @@ api.on('connection', function(spark) {
|
||||
}
|
||||
});
|
||||
|
||||
spark.on('node-ping', function(data){
|
||||
spark.emit('node-pong');
|
||||
});
|
||||
|
||||
spark.on('latency', function(data)
|
||||
{
|
||||
console.log('Latency: ', data.latency);
|
||||
console.log('got ping from ' + spark.id);
|
||||
|
||||
if(typeof data.id !== 'undefined')
|
||||
{
|
||||
var stats = Nodes.updateLatency(data.id, data.latency);
|
||||
|
||||
client.write({action: 'latency', data: stats});
|
||||
}
|
||||
});
|
||||
|
||||
spark.on('end', function(data)
|
||||
{
|
||||
var stats = Nodes.inactive(spark.id);
|
||||
|
@ -26,6 +26,16 @@ Collection.prototype.update = function(id, stats)
|
||||
return node.setStats(stats);
|
||||
}
|
||||
|
||||
Collection.prototype.updateLatency = function(id, latency)
|
||||
{
|
||||
var node = this.getNode({ id: id });
|
||||
|
||||
if(!node)
|
||||
return false;
|
||||
|
||||
return node.setLatency(latency);
|
||||
}
|
||||
|
||||
Collection.prototype.inactive = function(id)
|
||||
{
|
||||
var node = this.getNode({ spark: id });
|
||||
|
@ -104,6 +104,18 @@ Node.prototype.setStats = function(stats)
|
||||
return false;
|
||||
}
|
||||
|
||||
Node.prototype.setLatency = function(latency)
|
||||
{
|
||||
if(typeof latency !== 'undefined')
|
||||
{
|
||||
this.stats.latency = latency;
|
||||
|
||||
return { id: this.id, latency: latency };
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Node.prototype.getStats = function()
|
||||
{
|
||||
return {id: this.id, stats: this.stats};
|
||||
|
@ -85,6 +85,10 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
|
||||
$scope.nodes[findIndex({id: data.id})].stats = data.stats;
|
||||
toastr['error']("Node "+ $scope.nodes[findIndex({id: data.id})].info.name +" went away!", "Node connection was lost!");
|
||||
break;
|
||||
|
||||
case "latency":
|
||||
$scope.nodes[findIndex({id: data.id})].stats.latency = data.latency;
|
||||
break;
|
||||
}
|
||||
|
||||
updateStats();
|
||||
|
Loading…
Reference in New Issue
Block a user