From ccaec84906dcae0cf4930bd63fd3ea8267354a34 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Mon, 23 Apr 2018 07:44:53 +0900 Subject: [PATCH 1/2] Pool stats using the open-ethereum-pool api/stats --- app.json | 3 +++ lib/node.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/app.json b/app.json index 65f4f535..d73f4080 100644 --- a/app.json +++ b/app.json @@ -13,6 +13,9 @@ "NODE_ENV" : "production", "RPC_HOST" : "localhost", "RPC_PORT" : "8545", + "API_HOST" : "localhost", + "API_PORT" : "8080", + "API_URL" : "/api/stats", "LISTENING_PORT" : "30303", "INSTANCE_NAME" : "", "CONTACT_DETAILS" : "", diff --git a/lib/node.js b/lib/node.js index 59103aa2..3fb849df 100644 --- a/lib/node.js +++ b/lib/node.js @@ -2,6 +2,7 @@ require('./utils/logger.js'); +var http = require('http'); var os = require('os'); var Web3 = require('web3'); var web3; @@ -10,6 +11,7 @@ var _ = require('lodash'); var debounce = require('debounce'); var pjson = require('./../package.json'); var chalk = require('chalk'); +var poolOptions = null; var Primus = require('primus'), Emitter = require('primus-emit'), @@ -91,6 +93,10 @@ function Node () transactions: [], uncles: [] }, + pool: { + hashrate: 0, + minersTotal: 0 + }, syncing: false, uptime: 0 }; @@ -126,6 +132,7 @@ function Node () this._timeOffset = null; this.startWeb3Connection(); + this.setupPoolOptions(); return this; } @@ -140,6 +147,18 @@ Node.prototype.startWeb3Connection = function() this.checkWeb3Connection(); } +Node.prototype.setupPoolOptions = function() +{ + if (!process.env.NODE_TYPE || process.env.NODE_TYPE != 'pool') + return; + + poolOptions = { + hostname: (process.env.API_HOST || 'localhost'), + port: (process.env.API_PORT || 8080), + path: (process.env.API_URL || '/api/stats') + }; +} + Node.prototype.checkWeb3Connection = function() { var self = this; @@ -498,6 +517,23 @@ Node.prototype.getStats = function(forced) syncing: function (callback) { web3.eth.getSyncing(callback); + }, + pool: function (callback) + { + if (poolOptions == null) { + callback(null, {hashrate: 0, minersTotal: 0}); + return; + } + http.get(poolOptions, function(res) { + if (res.statusCode != 200) { + console.error('Status:', res.statusCode); + } + + res.on('data', function(data) { + var result = JSON.parse(data); + callback(null, result); + }); + }); } }, function (err, results) @@ -525,6 +561,11 @@ Node.prototype.getStats = function(forced) self.stats.hashrate = results.hashrate; self.stats.gasPrice = results.gasPrice.toString(10); + // setup pool stats + self.stats.pool = results.pool; + // sum hashares + self.stats.hashrate += results.pool.hashrate; + if(results.syncing !== false) { var sync = results.syncing; @@ -662,6 +703,7 @@ Node.prototype.prepareStats = function () hashrate: this.stats.hashrate, peers: this.stats.peers, gasPrice: this.stats.gasPrice, + pool: this.stats.pool, uptime: this.stats.uptime } }; From dcb51f09921704aa5f107a39679283333db97c31 Mon Sep 17 00:00:00 2001 From: Gons Date: Sun, 28 Oct 2018 15:14:49 +0900 Subject: [PATCH 2/2] Update lib/node.js -- 1d5d44537151b84a407e832bc3a35afa58e97dd4 patch errer - Couldn't get version case none coinbase --- lib/node.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/node.js b/lib/node.js index 0344a223..006c62d2 100644 --- a/lib/node.js +++ b/lib/node.js @@ -360,6 +360,11 @@ Node.prototype.getInfo = function() try { this.info.coinbase = web3.eth.coinbase; + } + catch (err) { + this.info.coinbase = null; + } + try { this.info.node = web3.version.node; this.info.net = web3.version.network; this.info.protocol = web3.toDecimal(web3.version.ethereum);