added update functionality (fixes #7)

pull/5/head
Marian Oancea 10 years ago
parent a3968373c0
commit 4cfe4948af
  1. 17
      app.js
  2. 2
      models/node.js
  3. 2
      public/js/controllers.js
  4. 28
      public/js/filters.js
  5. 2
      views/index.jade

@ -22,16 +22,21 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
var nodes = [], var nodes = [],
nodeStatus = []; nodeStatus = [],
nodeInterval;
for(i in config) { for(i in config) {
var node = new Node(config[i], i); nodes[i] = new Node(config[i], i);
console.log(node); console.log(nodes[i]);
node.update(); nodeStatus[i] = nodes[i].update();
nodes[i] = node;
nodeStatus[i] = node.info;
} }
nodeInterval = setInterval(function(){
for(i in nodes){
app.io.broadcast('update', nodes[i].update());
}
}, 10000);
app.get('/', function(req, res) { app.get('/', function(req, res) {
res.render('index', { title: 'Ethereum Network Status' }); res.render('index', { title: 'Ethereum Network Status' });
}); });

@ -6,7 +6,7 @@ var Node = function Node(options, id)
{ {
this.info = options; this.info = options;
this.info.geo = geoip.lookup(this.info.rpcHost); this.info.geo = geoip.lookup(this.info.rpcHost);
this.info.id = id; this.info.id = parseInt(id);
this.info.stats = { this.info.stats = {
active: false, active: false,
peers: 0, peers: 0,

@ -14,7 +14,7 @@ function StatsCtrl($scope, socket, _) {
}); });
socket.on('update', function(data){ socket.on('update', function(data){
$scope.nodes[data.node.id] = data.node; $scope.nodes[data.id] = data;
updateStats(); updateStats();
}); });

@ -3,34 +3,50 @@
/* Filters */ /* Filters */
angular.module('netStatsApp.filters', []) angular.module('netStatsApp.filters', [])
.filter('nodesActiveClass', function() {
return function(active, total) {
var ratio = active/total;
if(ratio >= 0.9)
return 'text-success';
if(ratio >= 0.75)
return 'text-info';
if(ratio >= 0.5)
return 'text-warning';
return 'text-danger';
};
})
.filter('mainClass', function() { .filter('mainClass', function() {
return function(node, bestBlock) { return function(node, bestBlock) {
if( ! node.active) if( ! node.active)
return 'text-danger'; return 'text-danger';
if( node.peers === 0) if(node.peers === 0)
return 'text-danger'; return 'text-danger';
return (node.peers <= 1 ? 'text-danger' : (node.peers > 1 && node.peers < 4 ? 'text-warning' : 'text-success')); return (node.peers <= 1 ? 'text-danger' : (node.peers > 1 && node.peers < 4 ? 'text-warning' : 'text-success'));
} };
}) })
.filter('peerClass', function() { .filter('peerClass', function() {
return function(peers) { return function(peers) {
return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success')); return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success'));
} };
}) })
.filter('miningClass', function() { .filter('miningClass', function() {
return function(mining) { return function(mining) {
return (! mining ? 'text-danger' : ''); return (! mining ? 'text-danger' : '');
} };
}) })
.filter('miningIconClass', function() { .filter('miningIconClass', function() {
return function(mining) { return function(mining) {
return (! mining ? 'icon-cancel' : 'icon-check'); return (! mining ? 'icon-cancel' : 'icon-check');
} };
}) })
.filter('blockClass', function() { .filter('blockClass', function() {
return function(current, best) { return function(current, best) {
return (best - current <= 1 ? '' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger')); return (best - current <= 1 ? '' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger'));
} };
}); });

@ -11,7 +11,7 @@ block content
div.clearfix div.clearfix
div.col-xs-6.stat-holder div.col-xs-6.stat-holder
div.row.big-info.nodesactive.text-success div.row.big-info.nodesactive(class="{{ nodesActive | nodesActiveClass : nodesTotal }}")
div.pull-left.icon-full-width div.pull-left.icon-full-width
i.icon-bulb i.icon-bulb
div.pull-left div.pull-left

Loading…
Cancel
Save