node added uptime history
This commit is contained in:
parent
7d0994dc24
commit
0b94a49ac2
@ -33,7 +33,7 @@ Collection.prototype.inactive = function(id)
|
|||||||
if(!node)
|
if(!node)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
node.stats.active = false;
|
node.setState(false);
|
||||||
|
|
||||||
return node.getStats();
|
return node.getStats();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,15 @@ var Node = function Node(data)
|
|||||||
uptime: 0,
|
uptime: 0,
|
||||||
lastUpdate: 0
|
lastUpdate: 0
|
||||||
};
|
};
|
||||||
|
this.uptime = {
|
||||||
|
started: null,
|
||||||
|
history: []
|
||||||
|
};
|
||||||
|
|
||||||
|
if(this.id === null) {
|
||||||
|
this.uptime.started = (new Date()).getTime();
|
||||||
|
this.setState(true);
|
||||||
|
}
|
||||||
|
|
||||||
if(typeof data.id !== 'undefined')
|
if(typeof data.id !== 'undefined')
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
@ -66,6 +75,9 @@ Node.prototype.setInfo = function(data)
|
|||||||
|
|
||||||
if(typeof data.spark !== 'undefined')
|
if(typeof data.spark !== 'undefined')
|
||||||
this.spark = data.spark;
|
this.spark = data.spark;
|
||||||
|
|
||||||
|
if(this.uptime.history.length > 0 && this.uptime.history[this.uptime.history.length - 1].status == 'down')
|
||||||
|
this.setState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node.prototype.getInfo = function()
|
Node.prototype.getInfo = function()
|
||||||
@ -77,7 +89,7 @@ Node.prototype.setStats = function(stats)
|
|||||||
{
|
{
|
||||||
if(typeof stats !== undefined && typeof stats.block !== undefined && typeof stats.block.number !== undefined)
|
if(typeof stats !== undefined && typeof stats.block !== undefined && typeof stats.block.number !== undefined)
|
||||||
{
|
{
|
||||||
if(stats.block.number !== this.stats.number){
|
if(stats.block.number !== this.stats.number) {
|
||||||
stats.block.received == (new Date()).getTime() - stats.block.arrival;
|
stats.block.received == (new Date()).getTime() - stats.block.arrival;
|
||||||
} else {
|
} else {
|
||||||
stats.block.received = this.stats.block.received;
|
stats.block.received = this.stats.block.received;
|
||||||
@ -96,4 +108,10 @@ Node.prototype.getStats = function()
|
|||||||
return {id: this.id, stats: this.stats};
|
return {id: this.id, stats: this.stats};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node.prototype.setState = function(active)
|
||||||
|
{
|
||||||
|
this.stats.active = active;
|
||||||
|
this.uptime.history.push({status: (active ? 'up' : 'down'), time: (new Date()).getTime()});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Node;
|
module.exports = Node;
|
||||||
|
Loading…
Reference in New Issue
Block a user