2
2
3
3
require ( './utils/logger.js' ) ;
4
4
5
+ var http = require ( 'http' ) ;
5
6
var os = require ( 'os' ) ;
6
7
var Web3 = require ( 'web3' ) ;
7
8
var web3 ;
@@ -10,6 +11,7 @@ var _ = require('lodash');
10
11
var debounce = require ( 'debounce' ) ;
11
12
var pjson = require ( './../package.json' ) ;
12
13
var chalk = require ( 'chalk' ) ;
14
+ var poolOptions = null ;
13
15
14
16
var Primus = require ( 'primus' ) ,
15
17
Emitter = require ( 'primus-emit' ) ,
@@ -91,6 +93,10 @@ function Node ()
91
93
transactions : [ ] ,
92
94
uncles : [ ]
93
95
} ,
96
+ pool : {
97
+ hashrate : 0 ,
98
+ minersTotal : 0
99
+ } ,
94
100
syncing : false ,
95
101
uptime : 0
96
102
} ;
@@ -126,6 +132,7 @@ function Node ()
126
132
this . _timeOffset = null ;
127
133
128
134
this . startWeb3Connection ( ) ;
135
+ this . setupPoolOptions ( ) ;
129
136
130
137
return this ;
131
138
}
@@ -140,6 +147,18 @@ Node.prototype.startWeb3Connection = function()
140
147
this . checkWeb3Connection ( ) ;
141
148
}
142
149
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
+
143
162
Node . prototype . checkWeb3Connection = function ( )
144
163
{
145
164
var self = this ;
@@ -498,6 +517,23 @@ Node.prototype.getStats = function(forced)
498
517
syncing : function ( callback )
499
518
{
500
519
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
+ } ) ;
501
537
}
502
538
} ,
503
539
function ( err , results )
@@ -525,6 +561,11 @@ Node.prototype.getStats = function(forced)
525
561
self . stats . hashrate = results . hashrate ;
526
562
self . stats . gasPrice = results . gasPrice . toString ( 10 ) ;
527
563
564
+ // setup pool stats
565
+ self . stats . pool = results . pool ;
566
+ // sum hashrates
567
+ self . stats . hashrate += results . pool . hashrate ;
568
+
528
569
if ( results . syncing !== false ) {
529
570
var sync = results . syncing ;
530
571
@@ -662,6 +703,7 @@ Node.prototype.prepareStats = function ()
662
703
hashrate : this . stats . hashrate ,
663
704
peers : this . stats . peers ,
664
705
gasPrice : this . stats . gasPrice ,
706
+ pool : this . stats . pool ,
665
707
uptime : this . stats . uptime
666
708
}
667
709
} ;
0 commit comments