Skip to content

Commit

Permalink
Merge pull request #17 from cubedro/master
Browse files Browse the repository at this point in the history
Update develop branch
  • Loading branch information
cubedro committed Feb 26, 2015
2 parents b8a1ae1 + 90d8845 commit 8f69eac
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.12"
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
eth-netstats
============

Ethereum Network Stats
============
[![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url]

To run via Docker

Expand All @@ -18,3 +17,8 @@ docker run --publish=3000:3000 eth-netstats
```

see the interface at http://localhost:3000

[travis-image]: https://travis-ci.org/cubedro/eth-netstats.svg
[travis-url]: https://travis-ci.org/cubedro/eth-netstats
[dep-image]: https://david-dm.org/cubedro/eth-netstats.svg
[dep-url]: https://david-dm.org/cubedro/eth-netstats
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ api = new Primus(server, {
});

api.use('emit', require('primus-emit'));
api.use('spark-latency', require('primus-spark-latency'));

var client = new Primus(server, {
transformer: 'websockets',
Expand All @@ -30,19 +31,22 @@ var client = new Primus(server, {
client.use('emit', require('primus-emit'));

api.on('connection', function(spark) {
console.log('Latency: ', spark.latency);
console.log(spark.id);
console.log(spark.address);
console.log(spark.query);

spark.on('hello', function(data)
{
console.log('Latency: ', spark.latency);
console.log('got hello data from ', spark.id);
console.log(data);

if(typeof data.id !== 'undefined' && typeof data.info !== 'undefined')
{
data.ip = spark.address.ip;
data.spark = spark.id;
data.latency = spark.latency;

var info = Nodes.add(data);
spark.emit('ready');
Expand All @@ -53,11 +57,13 @@ api.on('connection', function(spark) {

spark.on('update', function(data)
{
console.log('Latency: ', spark.latency);
console.log('got update from ' + spark.id);
console.log(data);

if(typeof data.id !== 'undefined' && typeof data.stats !== 'undefined')
{
data.stats.latency = spark.latency;
var stats = Nodes.update(data.id, data.stats);

client.write({action: 'update', data: stats});
Expand Down
8 changes: 7 additions & 1 deletion models/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ var Node = function Node(data)
number: 0,
gasLimit: 0,
timestamp: 0,
blocktime: 0
arrival: 0,
propagation: 0
},
blocktimeAvg: 0,
blockTimes: [],
difficulty: [],
latency: 0,
uptime: 0,
lastUpdate: 0
};
Expand All @@ -39,6 +42,9 @@ var Node = function Node(data)
if(typeof data.spark !== 'undefined')
this.spark = data.spark;

if(typeof data.latency !== 'undefined')
this.stats.latency = data.latency;

return this;
}

Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.8.1",
"debug": "~2.0.0",
"body-parser": "1.12.0",
"debug": "2.1.1",
"express": "^4.11.2",
"geoip-lite": "^1.1.4",
"jade": "~1.6.0",
"lodash": "^3.2.0",
"geoip-lite": "^1.1.5",
"jade": "^1.9.2",
"lodash": "^3.3.1",
"primus": "^2.4.12",
"primus-emit": "^0.1.2",
"serve-favicon": "~2.1.3",
"primus-spark-latency": "^0.1.1",
"serve-favicon": "^2.2.0",
"ws": "^0.7.1"
}
}
6 changes: 5 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ table td i {
.stat-holder {
width: 100%;
}
}
}

.ng-cloak {
display: none !important;
}
10 changes: 7 additions & 3 deletions public/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
$scope.nodes = [];
$scope.map = [];

$scope.timeout = setInterval(function(){
$scope.$apply();
}, 1000);

// Socket listeners
// ----------------

Expand Down Expand Up @@ -59,9 +63,9 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {

case "add":
if(addNewNode(data))
toastr['success']("New node connected!", "New node!");
toastr['success']("New node "+ $scope.nodes[findIndex({id: data.id})].info.name +" connected!", "New node!");
else
toastr['info']("Node reconnected!", "Node is back!");
toastr['info']("Node "+ $scope.nodes[findIndex({id: data.id})].info.name +" reconnected!", "Node is back!");
break;

case "update":
Expand All @@ -74,7 +78,7 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {

case "inactive":
$scope.nodes[findIndex({id: data.id})].stats = data.stats;
toastr['error']("Node went away!", "Node connection was lost!");
toastr['error']("Node "+ $scope.nodes[findIndex({id: data.id})].info.name +" went away!", "Node connection was lost!");
break;
}

Expand Down
37 changes: 36 additions & 1 deletion public/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,46 @@ angular.module('netStatsApp.filters', [])
return (typeof gas !== 'undefined' ? parseInt(gas) : '?');
}
})
.filter('latencyFilter', function() {
return function(stats) {
if(stats.active === false)
return 'offline';
else
return stats.latency + ' ms';
}
})
.filter('hashFilter', function() {
return function(hash) {
return hash.substr(0, 6) + '...' + hash.substr(58, 6);
}
})
.filter('timeClass', function() {
return function(timestamp) {
return timeClass(timestamp);
};
})
.filter('propagationTimeClass', function() {
return function(propagation) {
if(propagation <= 3000)
return 'text-success';

if(propagation <= 7000)
return 'text-warning';

return 'text-danger'
};
})
.filter('latencyClass', function() {
return function(time) {
if(time <= 100)
return 'text-success';

if(time <= 1000)
return 'text-warning';

return 'text-danger'
};
})
.filter('blockTimeFilter', function() {
return function(timestamp) {
if(timestamp === 0)
Expand All @@ -74,7 +109,7 @@ angular.module('netStatsApp.filters', [])
var diff = time - timestamp;

if(diff < 60)
return Math.round(diff) + ' s';
return Math.round(diff) + ' s ago';

return moment.duration(Math.round(diff), 's').humanize() + ' ago';
};
Expand Down
2 changes: 1 addition & 1 deletion public/js/lib/locale/en-gb.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
future : 'in %s',
past : '%s ago',
s : 'a few sec',
m : 'a min',
m : '1 min',
mm : '%d min',
h : '1 h',
hh : '%d h',
Expand Down
14 changes: 10 additions & 4 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ block content
i.icon-node(data-toggle="tooltip", data-placement="top", title="Node")
th
i.icon-laptop(data-toggle="tooltip", data-placement="top", title="Node type")
th
i.icon-gas(data-toggle="tooltip", data-placement="top", title="Node latency")
th
i.icon-mining(data-toggle="tooltip", data-placement="top", title="Is mining")
th
Expand All @@ -89,9 +91,11 @@ block content
th
i.icon-check-o(data-toggle="tooltip", data-placement="top", title="Block transactions")
th
i.icon-time(data-toggle="tooltip", data-placement="top", title="Last node time")
i.icon-time(data-toggle="tooltip", data-placement="top", title="Last block time")
th
i.icon-clock(data-toggle="tooltip", data-placement="top", title="Propagation time")
th
i.icon-clock(data-toggle="tooltip", data-placement="top", title="Up-time")
i.icon-bulb(data-toggle="tooltip", data-placement="top", title="Up-time")
tbody
tr(ng-repeat='node in nodes', class="{{ node.stats | mainClass : bestBlock }}")
td(rel="{{node.id}}")
Expand All @@ -100,14 +104,16 @@ block content
td
div.small(ng-bind-html="node.info.node | nodeVersion")
//- div.small {{node.info.os}}, {{node.info.os_v}}
td.small(class="{{ node.stats.latency | latencyClass }}") {{node.stats | latencyFilter}}
td(class="{{ node.stats.mining | miningClass }}")
i(class="{{ node.stats.mining | miningIconClass }}")
i.small(class="{{ node.stats.mining | miningIconClass }}")
td(class="{{ node.stats.peers | peerClass }}", style="padding-left: 18px;") {{node.stats.peers}}
td(style="padding-left: 18px;") {{node.stats.pending}}
td(class="{{ node.stats.block.number | blockClass : bestBlock }}") {{'#' + node.stats.block.number}}
td(class="{{ node.stats.block.number | blockClass : bestBlock }}").hidden-sm.hidden-xs
span.small {{node.stats.block.hash}}
span.small {{node.stats.block.hash | hashFilter}}
//- div.small Difficulty: {{node.stats.block.difficulty | gasFilter}} | Gas used: {{node.stats.block.gasUsed | gasFilter}} | Min gas price: {{node.stats.block.minGasPrice | gasFilter}} | Gas limit: {{node.stats.block.gasLimit | gasFilter}}
td(style="padding-left: 18px;") {{node.stats.block.txCount}}
td(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.timestamp | blockTimeFilter }}
td(class="{{ node.stats.block.propagation | propagationTimeClass }}") {{node.stats.block.propagation}} ms
td(class="{{ node.stats.uptime | upTimeClass }}") {{ node.stats.uptime | upTimeFilter }}

0 comments on commit 8f69eac

Please sign in to comment.