added stats as different method

This commit is contained in:
cubedro 2015-06-02 00:04:34 +03:00
parent 0925b738b9
commit 28447d6c43
6 changed files with 83 additions and 5 deletions

16
app.js
View File

@ -181,6 +181,22 @@ api.on('connection', function(spark) {
}
});
spark.on('stats', function(data)
{
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
{
var stats = Nodes.updateStats(data.id, data.stats);
if(stats !== false)
{
client.write({
action: 'stats',
data: stats
});
}
}
});
spark.on('history', function(data)
{
console.log("got history from " + data.id);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -70,6 +70,16 @@ Collection.prototype.updatePending = function(id, stats)
return node.setPending(stats);
}
Collection.prototype.updateStats = function(id, stats)
{
var node = this.getNode({ id: id });
if (!node)
return false;
return node.setBasicStats(stats);
}
Collection.prototype.addHistory = function(id, blocks)
{
var node = this.getNode({ id: id });

View File

@ -11,8 +11,8 @@ var Node = function Node(data)
this.geo = {}
this.stats = {
active: false,
listening: false,
mining: false,
hashrate: 0,
peers: 0,
pending: 0,
gasPrice: 0,
@ -181,6 +181,23 @@ Node.prototype.setPending = function(stats)
return false;
}
Node.prototype.setBasicStats = function(stats)
{
if( !_.isUndefined(stats) )
{
this.stats.active = stats.active;
this.stats.mining = stats.mining;
this.stats.hashrate = stats.hashrate;
this.stats.peers = stats.peers;
this.stats.gasPrice = stats.gasPrice;
this.stats.uptime = stats.uptime;
return this.getBasicStats();
}
return false;
}
Node.prototype.setLatency = function(latency)
{
if( !_.isUndefined(latency) )
@ -215,6 +232,21 @@ Node.prototype.getBlockStats = function()
};
}
Node.prototype.getBasicStats = function()
{
return {
id: this.id,
stats: {
active: this.stats.active,
mining: this.stats.mining,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
uptime: this.stats.uptime
}
};
}
Node.prototype.setState = function(active)
{
this.stats.active = active;

View File

@ -214,12 +214,32 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
{
var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.pending) )
if( !_.isUndefined(node) && !_.isUndefined(node.stats.pending) && !_.isUndefined(data.pending) )
$scope.nodes[index].stats.pending = data.pending;
}
break;
case "stats":
var index = findIndex({id: data.id});
if( !_.isUndefined(data.id) && index >= 0 )
{
var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) )
{
$scope.nodes[index].stats.active = data.stats.active;
$scope.nodes[index].stats.mining = data.stats.mining;
$scope.nodes[index].stats.hashrate = data.stats.hashrate;
$scope.nodes[index].stats.peers = data.stats.peers;
$scope.nodes[index].stats.gasPrice = data.stats.gasPrice;
$scope.nodes[index].stats.uptime = data.stats.uptime;
}
}
break;
case "info":
var index = findIndex({id: data.id});
@ -317,7 +337,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
break;
}
if( action !== "latency" && action !== "client-ping" )
if( action !== "latency" && action !== "pending" && action !== "client-ping" )
{
updateStats();
}