added uptime functionality

pull/5/head
Marian Oancea 10 years ago
parent 281a5d7f5b
commit 71ae336715
  1. 9
      models/node.js
  2. 1
      public/js/controllers.js
  3. 19
      public/js/filters.js
  4. 6
      views/index.jade

@ -15,6 +15,11 @@ var Node = function Node(options, id)
height: 0,
hash: '?',
timestamp: 0
},
uptime: {
down: 0,
inc: 0,
total: 0
}
}
@ -46,8 +51,12 @@ Node.prototype.update = function()
this.info.stats.active = true;
} else {
this.info.stats.active = false;
this.info.stats.uptime.down++;
}
this.info.stats.uptime.inc++;
this.info.stats.uptime.total = ((this.info.stats.uptime.inc - this.info.stats.uptime.down) / this.info.stats.uptime.inc) * 100;
return this.info;
};

@ -25,5 +25,6 @@ function StatsCtrl($scope, socket, _) {
$scope.nodesActive = _.filter($scope.nodes, function(node){ return node.stats.active == true; }).length;
$scope.bestBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.height); }).stats.block.height;
$scope.lastBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.timestamp); }).stats.block.timestamp;
$scope.upTimeTotal = _.reduce($scope.nodes, function(total, node){ return total + node.stats.uptime.total; }, 0) / $scope.nodes.length;
}
}

@ -54,7 +54,24 @@ angular.module('netStatsApp.filters', [])
return function(timestamp) {
return timeClass(timestamp);
};
}).filter('geoTooltip', function() {
})
.filter('upTimeFilter', function() {
return function(uptime) {
return Math.round(uptime) + '%';
};
})
.filter('upTimeClass', function() {
return function(uptime) {
if(uptime >= 90)
return 'text-success';
if(uptime >= 75)
return 'text-warning';
return 'text-danger';
};
})
.filter('geoTooltip', function() {
return function(geo) {
return geo.city + ", " + geo.country;
};

@ -35,12 +35,12 @@ block content
span.big-details(am-time-ago="lastBlock", am-preprocess="unix")
div.clearfix
div.col-xs-6.stat-holder
div.row.big-info.uptime.text-info
div.row.big-info.uptime(class="{{ upTimeTotal | upTimeClass }}")
div.pull-left.icon-full-width
i.icon-clock
div.pull-left
span.small-title up-time
span.big-details 100%
span.big-details {{ upTimeTotal | upTimeFilter }}
div.clearfix
div.clearfix
@ -84,4 +84,4 @@ block content
td(class="{{ node.stats.block.height | blockClass : bestBlock }}").hidden-sm.hidden-xs
span.small {{node.stats.block.hash}}
td(am-time-ago="node.stats.block.timestamp", am-preprocess="unix", class="{{ node.stats.block.timestamp | timeClass }}")
td {{ node.stats.active ? '100%' : '0%' }}
td(class="{{ node.stats.uptime.total | upTimeClass }}") {{ node.stats.uptime.total | upTimeFilter }}

Loading…
Cancel
Save