Skip to content

Commit 18e2897

Browse files
committed
Pool stats using the open-ethereum-pool api/stats
1 parent bdc192e commit 18e2897

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

app.json

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"NODE_ENV" : "production",
1414
"RPC_HOST" : "localhost",
1515
"RPC_PORT" : "8545",
16+
"API_HOST" : "localhost",
17+
"API_PORT" : "8080",
18+
"API_URL" : "/api/stats",
1619
"LISTENING_PORT" : "30303",
1720
"INSTANCE_NAME" : "",
1821
"CONTACT_DETAILS" : "",

lib/node.js

+42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require('./utils/logger.js');
44

5+
var http = require('http');
56
var os = require('os');
67
var Web3 = require('web3');
78
var web3;
@@ -10,6 +11,7 @@ var _ = require('lodash');
1011
var debounce = require('debounce');
1112
var pjson = require('./../package.json');
1213
var chalk = require('chalk');
14+
var poolOptions = null;
1315

1416
var Primus = require('primus'),
1517
Emitter = require('primus-emit'),
@@ -91,6 +93,10 @@ function Node ()
9193
transactions: [],
9294
uncles: []
9395
},
96+
pool: {
97+
hashrate: 0,
98+
minersTotal: 0
99+
},
94100
syncing: false,
95101
uptime: 0
96102
};
@@ -126,6 +132,7 @@ function Node ()
126132
this._timeOffset = null;
127133

128134
this.startWeb3Connection();
135+
this.setupPoolOptions();
129136

130137
return this;
131138
}
@@ -140,6 +147,18 @@ Node.prototype.startWeb3Connection = function()
140147
this.checkWeb3Connection();
141148
}
142149

150+
Node.prototype.setupPoolOptions = function()
151+
{
152+
if (!process.env.NODE_TYPE || process.env.NODE_TYPE != 'pool')
153+
return;
154+
155+
poolOptions = {
156+
hostname: (process.env.API_HOST || 'localhost'),
157+
port: (process.env.API_PORT || 8080),
158+
path: (process.env.API_URL || '/api/stats')
159+
};
160+
}
161+
143162
Node.prototype.checkWeb3Connection = function()
144163
{
145164
var self = this;
@@ -498,6 +517,23 @@ Node.prototype.getStats = function(forced)
498517
syncing: function (callback)
499518
{
500519
web3.eth.getSyncing(callback);
520+
},
521+
pool: function (callback)
522+
{
523+
if (poolOptions == null) {
524+
callback(null, {hashrate: 0, minersTotal: 0});
525+
return;
526+
}
527+
http.get(poolOptions, function(res) {
528+
if (res.statusCode != 200) {
529+
console.error('Status:', res.statusCode);
530+
}
531+
532+
res.on('data', function(data) {
533+
var result = JSON.parse(data);
534+
callback(null, result);
535+
});
536+
});
501537
}
502538
},
503539
function (err, results)
@@ -525,6 +561,11 @@ Node.prototype.getStats = function(forced)
525561
self.stats.hashrate = results.hashrate;
526562
self.stats.gasPrice = results.gasPrice.toString(10);
527563

564+
// setup pool stats
565+
self.stats.pool = results.pool;
566+
// sum hashrates
567+
self.stats.hashrate += results.pool.hashrate;
568+
528569
if(results.syncing !== false) {
529570
var sync = results.syncing;
530571

@@ -662,6 +703,7 @@ Node.prototype.prepareStats = function ()
662703
hashrate: this.stats.hashrate,
663704
peers: this.stats.peers,
664705
gasPrice: this.stats.gasPrice,
706+
pool: this.stats.pool,
665707
uptime: this.stats.uptime
666708
}
667709
};

0 commit comments

Comments
 (0)