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

View File

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

View File

@ -33,47 +33,51 @@ var History = function History(data)
History.prototype.add = function(block, id) History.prototype.add = function(block, id)
{ {
var historyBlock = this.search(block.number); if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined')
var now = (new Date()).getTime();
block.arrived = now;
block.received = now;
block.propagation = 0;
if(historyBlock)
{ {
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; var propIndex = _.findIndex(historyBlock.propagTimes, {node: id});
block.received = now;
block.propagation = now - historyBlock.block.received;
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 else
{ {
block.arrived = historyBlock.block.arrived; var item = {
block.received = historyBlock.propagTimes[propIndex].received; height: block.number,
block.propagation = historyBlock.propagTimes[propIndex].propagation; block: block,
} propagTimes: []
} }
else
{
var item = {
height: block.number,
block: block,
propagTimes: []
}
item.propagTimes.push({node: id, received: now, propagation: block.propagation}); item.propagTimes.push({node: id, received: now, propagation: block.propagation});
console.log('item: ', item); this._save(item);
this._save(item); }
} this.getNodePropagation(id);
this.getNodePropagation(id);
return block; return block;
}
return false;
} }
History.prototype._save = function(block) History.prototype._save = function(block)
@ -170,7 +174,29 @@ History.prototype.getUncleCount = function(id)
}) })
.value(); .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); var uncleBins = _.fill(Array(MAX_BINS), 0);

View File

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