http: improve info call.
This commit is contained in:
parent
322e74cbb7
commit
9988123b61
8
bin/cli
8
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.');
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user