From 9988123b61166670ff55aae009ad0d9c75aaa69f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 25 Oct 2016 08:40:08 -0700 Subject: [PATCH] http: improve info call. --- bin/cli | 8 ++++++++ lib/http/rpc.js | 3 +++ lib/http/server.js | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/bin/cli b/bin/cli index bca36443..598d83ff 100755 --- a/bin/cli +++ b/bin/cli @@ -27,6 +27,11 @@ CLI.prototype.log = function log(json) { console.log(JSON.stringify(json, null, 2)); }; +CLI.prototype.getInfo = co(function* getInfo() { + var info = yield this.client.getInfo(); + this.log(info); +}); + CLI.prototype.createWallet = co(function* createWallet() { var options = { id: this.argv[0] }; var wallet; @@ -506,6 +511,8 @@ CLI.prototype.handleNode = co(function* handleNode() { info = yield this.client.getInfo(); switch (this.argv.shift()) { + case 'info': + return yield this.getInfo(); case 'mkwallet': return yield this.createWallet(); case 'broadcast': @@ -531,6 +538,7 @@ CLI.prototype.handleNode = co(function* handleNode() { default: this.log('Unrecognized command.'); this.log('Commands:'); + this.log(' $ info: Get server info.'); this.log(' $ wallet create [id]: Create wallet.'); this.log(' $ broadcast [tx-hex]: Broadcast transaction.'); this.log(' $ mempool: Get mempool snapshot.'); diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 4d76b688..02026f17 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -4076,6 +4076,9 @@ RPC.prototype.getmemory = function getmemory(args) { if (args.help || args.length !== 0) return Promise.reject(new RPCError('getmemory')); + if (!process.memoryUsage) + return Promise.resolve({}); + mem = process.memoryUsage(); return Promise.resolve({ diff --git a/lib/http/server.js b/lib/http/server.js index 90e3f261..e04bb141 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -24,6 +24,7 @@ var Outpoint = require('../primitives/outpoint'); var HD = require('../hd/hd'); var Script = require('../script/script'); var crypto = require('../crypto/crypto'); +var time = require('../net/timedata'); var con = co.con; var RPC; @@ -552,15 +553,27 @@ HTTPServer.prototype._init = function _init() { })); this.get('/', function(req, res, send, next) { + var totalTX = this.mempool ? this.mempool.totalTX : 0; + var size = this.mempool ? this.mempool.getSize() : 0; + send(200, { version: constants.USER_VERSION, agent: constants.USER_AGENT, - services: this.pool.services, + services: this.pool.services.toString(2), network: this.network.type, height: this.chain.height, tip: this.chain.tip.rhash, - peers: this.pool.peers.all.length, - progress: this.chain.getProgress() + peers: this.pool.peers.regular.length + (this.pool.peers.load ? 1 : 0), + pendingPeers: this.pool.peers.pending.length, + leeches: this.pool.peers.leeches.length, + progress: this.chain.getProgress(), + mempoolTX: totalTX, + mempoolSize: size, + uptime: Math.floor(process.uptime()), + systemTime: utils.now(), + adjustedTime: time.now(), + timeOffset: time.offset, + memory: getMemory() }); }); @@ -1745,6 +1758,22 @@ function isWalletPath(req) { return false; } +function getMemory() { + var mem; + + if (!process.memoryUsage) + return {}; + + mem = process.memoryUsage(); + + return { + rss: utils.mb(mem.rss), + jsHeap: utils.mb(mem.heapUsed), + jsHeapTotal: utils.mb(mem.heapTotal), + nativeHeap: utils.mb(mem.rss - mem.heapTotal) + }; +} + /* * Expose */