diff --git a/config.json b/config.json index c1c566f..a790452 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { + "logLevel": "debug", "clustering": { "enabled": true, "forks": "auto" diff --git a/init.js b/init.js index e9f524b..bbaefbc 100644 --- a/init.js +++ b/init.js @@ -4,7 +4,7 @@ var cluster = require('cluster'); var posix = require('posix'); -var PoolLogger = require('./libs/logutils.js'); +var PoolLogger = require('./libs/logUtil.js'); var BlocknotifyListener = require('./libs/blocknotifyListener.js'); var WorkerListener = require('./libs/workerListener.js'); var PoolWorker = require('./libs/poolWorker.js'); @@ -14,15 +14,11 @@ var Website = require('./libs/website.js'); JSON.minify = JSON.minify || require("node-json-minify"); +var portalConfig = JSON.parse(JSON.minify(fs.readFileSync("config.json", {encoding: 'utf8'}))); var loggerInstance = new PoolLogger({ - 'default': true, - 'keys': { - //'client' : 'warning', - 'system' : true, - 'submitblock' : true - } + logLevel: portalConfig.logLevel }); var logDebug = loggerInstance.logDebug; @@ -174,7 +170,6 @@ var startWebsite = function(portalConfig, poolConfigs){ (function init(){ - var portalConfig = JSON.parse(JSON.minify(fs.readFileSync("config.json", {encoding: 'utf8'}))); var poolConfigs = buildPoolConfigs(); diff --git a/libs/api.js b/libs/api.js index da646f8..9fcac7d 100644 --- a/libs/api.js +++ b/libs/api.js @@ -1,18 +1,14 @@ -var express = require('express'); var os = require('os'); -var app = express(); - -app.get('/getstatus', function (req, res) { - res.send({ - 'loadavg': os.loadavg(), - 'freemem': os.freemem() - }); -}); -module.exports = { - start: function () { - app.listen(9000); - } -} +module.exports = function(logger, poolConfigs){ + + //Every 10 minutes clear out old hashrate stat data from redis + setInterval(function(){ + var tenMinutesAgo = (Date.now() / 1000 | 0) - (60 * 10); + connection.zremrangebyscore([coin + '_hashrate', '-inf', tenMinutesAgo]); + }, 10 * 60 * 1000); + + +}; diff --git a/libs/logutils.js b/libs/logUtil.js similarity index 63% rename from libs/logutils.js rename to libs/logUtil.js index 5ef890d..134d118 100644 --- a/libs/logutils.js +++ b/libs/logUtil.js @@ -39,35 +39,26 @@ var getSeverityColor = function(severity) { var PoolLogger = function (configuration) { + var logLevelInt = severityToInt(configuration.logLevel); + // privates var shouldLog = function(key, severity) { - var keyValue = configuration.keys[key]; - if (typeof(keyValue) === 'undefined') { - keyValue = configuration.default; - } - - if (typeof(keyValue) === 'boolean') { - return keyValue; - } else if (typeof(keyValue) === 'string') { - return severityToInt(severity) >= severityToInt(keyValue); - } - } + var severity = severityToInt(severity); + return severity >= logLevelInt; + }; var log = function(severity, key, poolName, text) { - if ( ! shouldLog(key, severity) ) { - // if this tag is set to not be logged or the default value is false then drop it! - //console.log(key+"DROPPED "+text + 'SEV' + severity); + if (!shouldLog(key, severity)) return; - } var desc = poolName ? '[' + poolName + '] ' : ''; console.log( - '\u001b['+getSeverityColor(severity)+'m' + - dateFormat(new Date(), 'yyyy-mm-dd HH:mm:ss') + - " ["+key+"]" + '\u001b[39m: ' + "\t" + - desc + - text); - } + '\u001b[' + getSeverityColor(severity) + 'm' + + dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss') + + " [" + key + "]" + '\u001b[39m: ' + "\t" + + desc + text + ); + }; // public diff --git a/libs/paymentProcessor.js b/libs/paymentProcessor.js index 8952eda..b9b9d6e 100644 --- a/libs/paymentProcessor.js +++ b/libs/paymentProcessor.js @@ -189,7 +189,7 @@ function SetupForPool(logger, poolOptions){ }, 0); var poolTotalRewards = rounds.reduce(function(p, c){ - return p + c.amount; + return p + c.amount * c.magnitude; }, 0); console.log(workerRewards); diff --git a/libs/shareProcessor.js b/libs/shareProcessor.js index ca9c055..dd58848 100644 --- a/libs/shareProcessor.js +++ b/libs/shareProcessor.js @@ -44,12 +44,6 @@ module.exports = function(logger, poolConfig){ connect(); - //Every 10 minutes clear out old hashrate stat data from redis - setInterval(function(){ - var tenMinutesAgo = (Date.now() / 1000 | 0) - (60 * 10); - connection.zremrangebyscore([coin + '_hashrate', '-inf', tenMinutesAgo]); - }, 10 * 60 * 1000); - this.handleShare = function(isValidShare, isValidBlock, shareData){ diff --git a/libs/website.js b/libs/website.js index 635f3d6..c4fd2c0 100644 --- a/libs/website.js +++ b/libs/website.js @@ -29,6 +29,7 @@ var dot = require('dot'); var express = require('express'); + module.exports = function(logger){ var portalConfig = JSON.parse(process.env.portalConfig);