From 6358cf2cc332db02cf960c97352efae0ddd675f6 Mon Sep 17 00:00:00 2001 From: Mike Teehan Date: Sat, 17 Feb 2018 15:26:41 -0500 Subject: [PATCH 1/3] Added a simple http+json server option for monitoring purposes --- config_example.json | 3 +++ index.html | 47 +++++++++++++++++++++++++++++++++++++++++++++ proxy.js | 43 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 index.html diff --git a/config_example.json b/config_example.json index 6fbcabe..4ca07d9 100644 --- a/config_example.json +++ b/config_example.json @@ -48,6 +48,9 @@ "bindAddress": "0.0.0.0", "developerShare": 1, "daemonAddress": "127.0.0.1:18081", + "httpEnable": false, + "httpAddress": "127.0.0.1", + "httpPort": "8080", "coinSettings": { "xmr":{ "minDiff": 100, diff --git a/index.html b/index.html new file mode 100644 index 0000000..25cfa85 --- /dev/null +++ b/index.html @@ -0,0 +1,47 @@ + + + + XNP Hashrate Monitor + + + +
+ + + + + diff --git a/proxy.js b/proxy.js index beceb35..7229ac3 100644 --- a/proxy.js +++ b/proxy.js @@ -2,6 +2,7 @@ const cluster = require('cluster'); const net = require('net'); const tls = require('tls'); +const http = require('http'); const fs = require('fs'); const async = require('async'); const uuidV4 = require('uuid/v4'); @@ -578,7 +579,13 @@ function balanceWorkers(){ } } -function enumerateWorkerStats(){ +function enumerateWorkerStats() { + // here we do a bit of a hack and "cache" the activeWorkers + // this file is parsed for the http://host/json endpoint + fs.writeFile("workers.json", JSON.stringify(activeWorkers), function(err) { + if(err) + return console.log(err); + }); let stats, global_stats = {miners: 0, hashes: 0, hashRate: 0, diff: 0}; for (let poolID in activeWorkers){ if (activeWorkers.hasOwnProperty(poolID)){ @@ -803,7 +810,8 @@ function Miner(id, params, ip, pushMessage, portData, minerSocket) { lastShare: this.lastShareTime, coin: this.coin, pool: this.pool, - id: this.id + id: this.id, + password: this.password }; }; @@ -952,6 +960,33 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage, m } } +function activateHTTP() { + var jsonServer = http.createServer((req, res) => { + if(req.url == "/") { + res.writeHead(200, {'Content-type':'text/html'}); + fs.readFile('index.html', 'utf8', function(err, contents) { + res.write(contents); + res.end(); + }) + } else if(req.url.substring(0, 5) == "/json") { + fs.readFile('workers.json', 'utf8', (err, data) => { + if(err) { + res.writeHead(503); + } else { + res.writeHead(200, {'Content-type':'application/json'}); + res.write(data + "\r\n"); + } + res.end(); + }); + } else { + res.writeHead(404); + res.end(); + } + }); + + jsonServer.listen(global.config.httpPort || "8080", global.config.httpAddress || "localhost") +} + function activatePorts() { /* Reads the current open ports, and then activates any that aren't active yet @@ -990,7 +1025,7 @@ function activatePorts() { socket.write(sendData); }; handleMinerData(jsonData.method, jsonData.params, socket.remoteAddress, portData, sendReply, pushMessage, minerSocket); - }; + }; function socketConn(socket) { socket.setKeepAlive(true); @@ -1183,4 +1218,6 @@ if (cluster.isMaster) { }, 10000); setInterval(checkActivePools, 90000); activatePorts(); + if(global.config.httpEnable) + activateHTTP(); } From 191a6cb05f5e75a50ece3145c104856b62e8cdca Mon Sep 17 00:00:00 2001 From: Mike Teehan Date: Sat, 17 Feb 2018 16:56:14 -0500 Subject: [PATCH 2/3] Tiny fixes --- index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 25cfa85..32acba2 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,7 @@ (($) => { var $disp = $('#displaytable').DataTable({ + pageLength: 50, ajax: { url: "/json", type: "GET", @@ -26,7 +27,7 @@ function parseJSON(json) { var res = []; - var worker, miner, name; + var worker, miner, row, name; for(var workerid in json) { worker = json[workerid]; if(worker.length == 0) continue; From 3e3719bbbe14886e792d08b88d948adc4ec8154e Mon Sep 17 00:00:00 2001 From: Mike Teehan Date: Mon, 19 Feb 2018 19:00:01 -0500 Subject: [PATCH 3/3] Added a footer row and some styling to the main datatable --- index.html | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 32acba2..e610759 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ -
+