From 71ae33671592797779df6be510291e3ac3af7c27 Mon Sep 17 00:00:00 2001 From: Marian Oancea Date: Thu, 5 Feb 2015 13:05:21 +0200 Subject: [PATCH] added uptime functionality --- models/node.js | 9 +++++++++ public/js/controllers.js | 1 + public/js/filters.js | 19 ++++++++++++++++++- views/index.jade | 6 +++--- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/models/node.js b/models/node.js index 4506591..750e1d8 100644 --- a/models/node.js +++ b/models/node.js @@ -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; }; diff --git a/public/js/controllers.js b/public/js/controllers.js index 237713c..ebcefe1 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -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; } } \ No newline at end of file diff --git a/public/js/filters.js b/public/js/filters.js index 12268bc..189581b 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -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; }; diff --git a/views/index.jade b/views/index.jade index f01d72f..a88b483 100644 --- a/views/index.jade +++ b/views/index.jade @@ -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 }}