Merge pull request #34 from cubedro/develop

Added latency update
pull/5/head
Marian OANCΞA 10 years ago
commit 2aa72209a4
  1. 17
      app.js
  2. 10
      models/collection.js
  3. 12
      models/node.js
  4. 4
      public/js/controllers.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…
Cancel
Save