From b4bdc00fe063e2bda1e37f87bc68366ace66880d Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Sun, 11 Aug 2019 17:21:21 -0400 Subject: [PATCH] remove distracting, unmaintained influx integration, Fix #121 --- .env-sample | 10 --- app.js | 179 -------------------------------------------- app/credentials.js | 20 ----- app/utils.js | 39 ---------- bin/cli.js | 9 --- npm-shrinkwrap.json | 5 -- package.json | 1 - 7 files changed, 263 deletions(-) diff --git a/.env-sample b/.env-sample index 9537fa9..3c76162 100644 --- a/.env-sample +++ b/.env-sample @@ -24,16 +24,6 @@ BTCEXP_ADDRESS_API=(electrumx|blockchain.com|blockcypher.com) # used if BTCEXP_ADDRESS_API=electrumx #BTCEXP_ELECTRUMX_SERVERS=tls://electrumx.server.com:50002,tcp://127.0.0.1:50001,... - -# Optional InfluxDB Credentials (URI -OR- HOST/PORT/DBNAME/USER/PASS) -#BTCEXP_ENABLE_INFLUXDB=true -#BTCEXP_INFLUXDB_URI=influx://username:password@127.0.0.1:8086 -#BTCEXP_INFLUXDB_HOST=127.0.0.1 -#BTCEXP_INFLUXDB_PORT=8086 -#BTCEXP_INFLUXDB_DBNAME=influxdb -#BTCEXP_INFLUXDB_USER=dbuser -#BTCEXP_INFLUXDB_PASS=dbpassword - # Set number of concurrent RPC requests. Should be lower than your node's "rpcworkqueue" value. # The default for this value is 10, aiming to be less than Bitcoin Core's default rpcworkqueue=16. #BTCEXP_RPC_CONCURRENCY=10 diff --git a/app.js b/app.js index 3101cdf..13db2ab 100755 --- a/app.js +++ b/app.js @@ -42,7 +42,6 @@ var request = require("request"); var qrcode = require("qrcode"); var addressApi = require("./app/api/addressApi.js"); var electrumAddressApi = require("./app/api/electrumAddressApi.js"); -var Influx = require("influx"); var coreApi = require("./app/api/coreApi.js"); var auth = require('./app/auth.js'); @@ -85,157 +84,8 @@ app.use(express.static(path.join(__dirname, 'public'))); process.on("unhandledRejection", (reason, p) => { debugLog("Unhandled Rejection at: Promise", p, "reason:", reason, "stack:", (reason != null ? reason.stack : "null")); - - if (global.influxdb) { - var points = []; - points.push({ - measurement:`express.unhandled_rejection`, - tags:{app:("btc-rpc-explorer." + global.config.coin)}, - fields:{count:1} - }); - - global.influxdb.writePoints(points).catch(err => { - debugLog(`Error saving data to InfluxDB: ${err.stack}`); - }); - } }); - -function logNetworkStats() { - if (global.influxdb) { - var promises = []; - - promises.push(coreApi.getMempoolInfo()); - promises.push(coreApi.getMiningInfo()); - - promises.push(coreApi.getBlockchainInfo()); - - Promise.all(promises).then(function(promiseResults) { - var mempoolInfo = promiseResults[0]; - var miningInfo = promiseResults[1]; - var blockchainInfo = promiseResults[2]; - - //debugLog("mempoolInfo: " + JSON.stringify(mempoolInfo)); - //debugLog("miningInfo: " + JSON.stringify(miningInfo)); - //debugLog("blockchainInfo: " + JSON.stringify(blockchainInfo)); - - var points = []; - - var mempoolMapping = {size:"tx_count", bytes:"tx_vsize_total", usage:"total_memory_usage"}; - for (var key in mempoolInfo) { - try { - if (mempoolMapping[key]) { - points.push({measurement:`${global.coinConfig.name.toLowerCase()}.mempool.${mempoolMapping[key]}`, fields:{value:mempoolInfo[key]}}); - } - } catch (err) { - utils.logError("3ourhewe", err, {key:key, desc:"Error mapping mempool info"}); - } - } - - var miningMapping = { - difficulty:{ - name:"mining_difficulty", - transform:function(rawval) {return parseFloat(rawval);} - }, - networkhashps:{ - name:"networkhashps", - transform:function(rawval) {return parseFloat(rawval);} - } - }; - - for (var key in miningInfo) { - try { - if (miningMapping[key]) { - points.push({measurement:`${global.coinConfig.name.toLowerCase()}.mining.${miningMapping[key].name}`, fields:{value:miningMapping[key].transform(miningInfo[key])}}); - } - } catch (err) { - utils.logError("weoufbebfde4", err, {key:key, desc:"Error mapping mining info"}); - } - } - - var blockchainMapping = {size_on_disk:"size_on_disk"}; - for (var key in blockchainInfo) { - try { - if (blockchainMapping[key]) { - points.push({measurement:`${global.coinConfig.name.toLowerCase()}.blockchain.${blockchainMapping[key]}`, fields:{value:blockchainInfo[key]}}); - } - } catch (err) { - utils.logError("3heuuh4wwds", err, {key:key, desc:"Error mapping blockchain info"}); - } - } - - //debugLog("Points to send to InfluxDB: " + JSON.stringify(points, null, 4)); - - global.influxdb.writePoints(points).catch(err => { - utils.logError("w083rhewhee", err, {desc:"Error saving data to InfluxDB"}); - }); - }).catch(err => { - utils.logError("u2h3rfsd", err); - }); - } -} - -function logBlockStats() { - if (global.influxdb) { - if (global.blockStatsStatus == null) { - global.blockStatsStatus = {currentBlock:-1}; - } - - coreApi.getBlockchainInfo().then(function(getblockchaininfo) { - var blockHeights = []; - if (getblockchaininfo.blocks) { - for (var i = 0; i < 5; i++) { - blockHeights.push(getblockchaininfo.blocks - i); - } - } - - coreApi.getBlocksByHeight(blockHeights).then(function(blocks) { - var points = []; - - for (var i = 0; i < blocks.length; i++) { - var block = blocks[i]; - - var totalfees = new Decimal(parseFloat(block.totalFees)); - var blockreward = new Decimal(parseFloat(global.coinConfig.blockRewardFunction(block.height))); - var timestamp = new Date(block.time * 1000); - - var blockInfo = { - strippedsize:block.strippedsize, - size:block.size, - weight:block.weight, - version:block.version, - nonce:block.nonce, - txcount:block.nTx, - totalfees:totalfees.toNumber(), - avgfee:(block.totalFees / block.nTx), - avgfeeperweight:(block.totalFees / block.weight), - avgfeepersize:(block.totalFees / block.size), - avgtxsize:(block.size / block.nTx), - avgtxweight:(block.weight / block.nTx), - blockreward:blockreward.toNumber(), - timemediantimediff:(block.time - block.mediantime), - witnessdatasize:(block.size - block.strippedsize), - feeratio:totalfees.dividedBy(totalfees.plus(blockreward)).toNumber() - }; - - for (var key in blockInfo) { - points.push({measurement:`${global.coinConfig.name.toLowerCase()}.blocks.${key}`, fields:{value:blockInfo[key]}, timestamp:timestamp}); - } - - //debugLog("block: " + block.height + ": " + JSON.stringify(blockInfo, null, 4)); - //debugLog("points: " + JSON.stringify(points, null, 4)); - } - - global.influxdb.writePoints(points).catch(err => { - utils.logError("3ru032hfudge", err, {desc:"Error saving data to InfluxDB"}); - }); - }); - }).catch(function(err) { - utils.logError("23uhsdsgde", err); - }); - } -} - function loadMiningPoolConfigs() { global.miningPoolsConfigs = []; @@ -307,22 +157,9 @@ app.runOnStartup = function() { global.client = new bitcoinCore(rpcClientProperties); - if (config.credentials.influxdb.active) { - global.influxdb = new Influx.InfluxDB(config.credentials.influxdb); - - debugLog(`Connected to InfluxDB: ${config.credentials.influxdb.host}:${config.credentials.influxdb.port}/${config.credentials.influxdb.database}`); - } - coreApi.getNetworkInfo().then(function(getnetworkinfo) { debugLog(`Connected via RPC to node. Basic info: version=${getnetworkinfo.version}, subversion=${getnetworkinfo.subversion}, protocolversion=${getnetworkinfo.protocolversion}, services=${getnetworkinfo.localservices}`); - if (global.influxdb != null) { - logNetworkStats(); - setInterval(logNetworkStats, 1 * 60000); - - logBlockStats(); - setInterval(logBlockStats, 5 * 60000); - } }).catch(function(err) { utils.logError("32ugegdfsde", err); }); @@ -411,9 +248,6 @@ app.runOnStartup = function() { // refresh exchange rate periodically setInterval(utils.refreshExchangeRates, 1800000); - utils.logAppStats(); - setInterval(utils.logAppStats, 5000); - utils.logMemoryUsage(); setInterval(utils.logMemoryUsage, 5000); }; @@ -537,19 +371,6 @@ app.use(function(req, res, next) { var memdiff = process.memoryUsage().heapUsed - req.startMem; debugPerfLog("Finished action '%s' in %d ms", req.path, time); - - if (global.influxdb) { - var points = []; - points.push({ - measurement:`express.request`, - tags:{app:("btc-rpc-explorer." + global.config.coin), host:req.hostname, path:req.path, userAgent:req.headers['user-agent']}, - fields:{count:1, duration:time, memdiff:memdiff} - }); - - global.influxdb.writePoints(points).catch(err => { - utils.logError("3rew08uhfeghd", err, {desc:"Error saving data to InfluxDB"}); - }); - } }); /// catch 404 and forwarding to error handler diff --git a/app/credentials.js b/app/credentials.js index b725370..d442fd1 100644 --- a/app/credentials.js +++ b/app/credentials.js @@ -5,17 +5,6 @@ var url = require('url'); var btcUri = process.env.BTCEXP_BITCOIND_URI ? url.parse(process.env.BTCEXP_BITCOIND_URI, true) : { query: { } }; var btcAuth = btcUri.auth ? btcUri.auth.split(':') : []; -var ifxUri = process.env.BTCEXP_INFLUXDB_URI ? url.parse(process.env.BTCEXP_INFLUXDB_URI, true) : { query: { } }; -var ifxAuth = ifxUri.auth ? ifxUri.auth.split(':') : []; - -var ifxActive = false; -if (process.env.BTCEXP_ENABLE_INFLUXDB != null) { - ifxActive = (process.env.BTCEXP_ENABLE_INFLUXDB.toLowerCase() == "true"); - -} else { - ifxActive = Object.keys(process.env).some(k => k.startsWith('BTCEXP_INFLUXDB_')); -} - module.exports = { rpc: { host: btcUri.hostname || process.env.BTCEXP_BITCOIND_HOST || "127.0.0.1", @@ -26,15 +15,6 @@ module.exports = { timeout: parseInt(btcUri.query.timeout || process.env.BTCEXP_BITCOIND_RPC_TIMEOUT || 5000), }, - influxdb:{ - active: ifxActive, - host: ifxUri.hostname || process.env.BTCEXP_INFLUXDB_HOST || "127.0.0.1", - port: ifxUri.port || process.env.BTCEXP_INFLUXDB_PORT || 8086, - database: ifxUri.pathname && ifxUri.pathname.substr(1) || process.env.BTCEXP_INFLUXDB_DBNAME || "influxdb", - username: ifxAuth[0] || process.env.BTCEXP_INFLUXDB_USER || "admin", - password: ifxAuth[1] || process.env.BTCEXP_INFLUXDB_PASS || "admin" - }, - // optional: enter your api access key from ipstack.com below // to include a map of the estimated locations of your node's // peers diff --git a/app/utils.js b/app/utils.js index 73eed85..0efaab9 100644 --- a/app/utils.js +++ b/app/utils.js @@ -220,28 +220,6 @@ function seededRandomIntBetween(seed, min, max) { return (min + (max - min) * rand); } -function logAppStats() { - if (global.influxdb) { - var points = []; - - points.push({ - measurement:`app.memory_usage`, - tags:{app:("btc-rpc-explorer." + global.config.coin)}, - fields:process.memoryUsage() - }); - - points.push({ - measurement:`app.uptime`, - tags:{app:("btc-rpc-explorer." + global.config.coin)}, - fields:{value:Math.floor(process.uptime())} - }); - - global.influxdb.writePoints(points).catch(err => { - logError("3ru3hfgde", err, {desc:"Error saving data to InfluxDB"}); - }); - } -} - function ellipsize(str, length) { if (str.length <= length) { return str; @@ -367,22 +345,6 @@ function refreshExchangeRates() { global.exchangeRates = exchangeRates; global.exchangeRatesUpdateTime = new Date(); - if (global.influxdb) { - var points = []; - for (var key in exchangeRates) { - points.push({ - measurement: `exchange_rates.${coins[config.coin].ticker.toLowerCase()}_${key.toLowerCase()}`, - fields:{value:parseFloat(exchangeRates[key])} - }); - } - - //debugLog("pts: " + JSON.stringify(points)); - - global.influxdb.writePoints(points).catch(err => { - logError("32o3h9ehf9ed", err, {desc:"Error saving data to InfluxDB"}); - }); - } - debugLog("Using exchange rates: " + JSON.stringify(global.exchangeRates) + " starting at " + global.exchangeRatesUpdateTime); } else { @@ -608,7 +570,6 @@ module.exports = { formatCurrencyAmountInSmallestUnits: formatCurrencyAmountInSmallestUnits, seededRandom: seededRandom, seededRandomIntBetween: seededRandomIntBetween, - logAppStats: logAppStats, logMemoryUsage: logMemoryUsage, getMinerFromCoinbaseTx: getMinerFromCoinbaseTx, getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight, diff --git a/bin/cli.js b/bin/cli.js index ad610b2..c866254 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -31,14 +31,6 @@ const args = require('meow')(` --ganalytics-tracking tracking id for google analytics [default: disabled] --sentry-url sentry url [default: disabled] - --enable-influxdb enable influxdb for logging network stats [default: false] - --influxdb-uri connection URI for influxdb (overrides the options below) - --influxdb-host hostname for influxdb [default: 127.0.0.1] - --influxdb-port port for influxdb [default: 8086] - --influxdb-user username for influxdb [default: admin] - --influxdb-pass password for influxdb [default: admin] - --influxdb-dbname database name for influxdb [default: influxdb] - -e, --node-env nodejs environment mode [default: production] -h, --help output usage information -v, --version output version number @@ -50,7 +42,6 @@ const args = require('meow')(` Or using connection URIs $ btc-rpc-explorer -b bitcoin://bob:myPassword@127.0.0.1:18443/ $ btc-rpc-explorer -b bitcoin://127.0.0.1:18443/?cookie=$HOME/.bitcoin/regtest/.cookie - $ btc-rpc-explorer --influxdb-uri influx://bob:myPassword@127.0.0.1:8086/dbName All options may also be specified as environment variables $ BTCEXP_PORT=8080 BTCEXP_BITCOIND_PORT=18443 BTCEXP_BITCOIND_COOKIE=~/.bitcoin/regtest/.cookie btc-rpc-explorer diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index ec3af22..04d3211 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1336,11 +1336,6 @@ "wrappy": "1" } }, - "influx": { - "version": "5.0.7", - "resolved": "https://registry.npmjs.org/influx/-/influx-5.0.7.tgz", - "integrity": "sha1-NeZfa/E8uqF2MQi1WWqAanJ6Upo=" - }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", diff --git a/package.json b/package.json index aaade8f..6e9372d 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "electrum-client": "github:chaintools/node-electrum-client#43a999036f9c5", "express": "^4.17.1", "express-session": "1.16.1", - "influx": "5.0.7", "jstransformer-markdown-it": "^2.1.0", "lru-cache": "5.1.1", "meow": "^5.0.0",