Merge pull request #167 from cubedro/develop

Added stats as different method
pull/5/head
Marian OANCΞA 10 years ago
commit 48fe8bdddb
  1. 16
      app.js
  2. 2
      dist/js/netstats.min.js
  3. 2
      dist/js/netstats.min.js.map
  4. 10
      models/collection.js
  5. 34
      models/node.js
  6. 24
      src/js/controllers.js

@ -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

@ -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 });

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

@ -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();
}

Loading…
Cancel
Save