Merge pull request #102 from cubedro/develop

Better error handling and logging
This commit is contained in:
Marian OANCΞA 2015-04-28 03:58:36 +03:00
commit 0fda04414b
4 changed files with 74 additions and 47 deletions

23
app.js
View File

@ -43,7 +43,7 @@ api.on('connection', function(spark) {
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);
if(typeof data.secret === 'undefined' || data.secret !== WS_SECRET)
@ -75,20 +75,23 @@ api.on('connection', function(spark) {
spark.on('update', function(data)
{
console.log('Latency: ', spark.latency);
console.log('got update from ' + spark.id);
console.log('Got update from ' + spark.id);
if(typeof data.id !== 'undefined' && typeof data.stats !== 'undefined')
{
data.stats.latency = spark.latency;
var stats = Nodes.update(data.id, data.stats);
client.write({action: 'update', data: stats});
if(stats !== false)
{
client.write({action: 'update', data: stats});
var blockPropagationChart = Nodes.blockPropagationChart();
client.write({action: 'blockPropagationChart', data: blockPropagationChart});
var blockPropagationChart = Nodes.blockPropagationChart();
client.write({action: 'blockPropagationChart', data: blockPropagationChart});
var uncleCount = Nodes.getUncleCount();
client.write({action: 'uncleCount', data: uncleCount});
var uncleCount = Nodes.getUncleCount();
client.write({action: 'uncleCount', data: uncleCount});
}
}
});
@ -98,9 +101,6 @@ api.on('connection', function(spark) {
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);
@ -123,9 +123,6 @@ client.on('connection', function(spark) {
console.log(spark.query);
spark.on('ready', function(data){
console.log('got hello data from ' + spark.id);
console.log(data);
spark.emit('init', {nodes: Nodes.all()});
var blockPropagationChart = Nodes.blockPropagationChart();

View File

@ -27,6 +27,10 @@ Collection.prototype.update = function(id, stats)
return false;
var block = this._history.add(stats.block, id);
if(! block)
return false;
var propagationHistory = this._history.getNodePropagation(id);
stats.block.arrived = block.arrived;

View File

@ -33,47 +33,51 @@ var History = function History(data)
History.prototype.add = function(block, id)
{
var historyBlock = this.search(block.number);
var now = (new Date()).getTime();
block.arrived = now;
block.received = now;
block.propagation = 0;
if(historyBlock)
if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined')
{
var propIndex = _.findIndex(historyBlock.propagTimes, {node: id});
var historyBlock = this.search(block.number);
if(propIndex === -1)
var now = (new Date()).getTime();
block.arrived = now;
block.received = now;
block.propagation = 0;
if(historyBlock)
{
block.arrived = historyBlock.block.arrived;
block.received = now;
block.propagation = now - historyBlock.block.received;
var propIndex = _.findIndex(historyBlock.propagTimes, {node: id});
historyBlock.propagTimes.push({node: id, received: now, propagation: block.propagation});
if(propIndex === -1)
{
block.arrived = historyBlock.block.arrived;
block.received = now;
block.propagation = now - historyBlock.block.received;
historyBlock.propagTimes.push({node: id, received: now, propagation: block.propagation});
}
else
{
block.arrived = historyBlock.block.arrived;
block.received = historyBlock.propagTimes[propIndex].received;
block.propagation = historyBlock.propagTimes[propIndex].propagation;
}
}
else
{
block.arrived = historyBlock.block.arrived;
block.received = historyBlock.propagTimes[propIndex].received;
block.propagation = historyBlock.propagTimes[propIndex].propagation;
}
}
else
{
var item = {
height: block.number,
block: block,
propagTimes: []
}
var item = {
height: block.number,
block: block,
propagTimes: []
}
item.propagTimes.push({node: id, received: now, propagation: block.propagation});
console.log('item: ', item);
this._save(item);
}
this.getNodePropagation(id);
item.propagTimes.push({node: id, received: now, propagation: block.propagation});
this._save(item);
}
this.getNodePropagation(id);
return block;
return block;
}
return false;
}
History.prototype._save = function(block)
@ -170,7 +174,29 @@ History.prototype.getUncleCount = function(id)
})
.value();
console.log(uncles);
var uncleBins = _.fill(Array(MAX_BINS), 0);
var sumMapper = function(array, key) {
uncleBins[key] = _.sum(array);
return _.sum(array);
};
_.map(_.chunk(uncles, MAX_UNCLES_PER_BIN), sumMapper);
return uncleBins;
}
History.prototype.getTransactionsCount = function(id)
{
var uncles = _(this._items)
.sortByOrder('height', false)
.slice(0, MAX_BINS - 1)
.reverse()
.map(function(item)
{
return item.block.transactions.length;
})
.value();
var uncleBins = _.fill(Array(MAX_BINS), 0);

View File

@ -1,7 +1,7 @@
{
"name": "eth-netstats",
"description": "Ethereum Network Intelligence dashboard",
"version": "0.0.3",
"version": "0.0.4",
"private": true,
"engines": {
"node": "0.12.0",