Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

feat: more status command output #124

Merged
merged 48 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
adc76a4
feat: add more masternode status output
strophy Aug 18, 2020
e48cdd4
Merge branch 'v0.15-dev' of github.com:dashevo/mn-bootstrap into stat…
strophy Aug 18, 2020
55fd6a7
feat: add masternode status
strophy Aug 18, 2020
b279c49
fix: handle sentinel success case
strophy Aug 18, 2020
2726873
Merge branch 'v0.15-dev' of github.com:dashevo/mn-bootstrap into stat…
strophy Aug 19, 2020
0daa6bb
feat: add port check
strophy Aug 19, 2020
7d2609d
refactor: use JSON where possible
strophy Aug 20, 2020
82c02f5
feat: show dmn state
strophy Aug 20, 2020
f9fa44d
fix: syntax
strophy Aug 20, 2020
7ab1567
feat: show tendermint status
strophy Aug 21, 2020
761505b
feat: use RPC instead of exec in container
strophy Aug 24, 2020
1374d9d
feat: show docker image and version
strophy Aug 24, 2020
c81d700
refactor: get image & version from docker inspect
strophy Aug 25, 2020
2fd9b86
refactor: go back to docker exec instead of RPC
strophy Aug 25, 2020
9ac4226
feat: port check for tendermint
strophy Aug 25, 2020
a0b2bcf
feat: add tendermint app hash
strophy Aug 26, 2020
611284b
feat: support arbitrary port for tendermint
strophy Aug 26, 2020
79f8355
fix: show tag in image column
strophy Aug 27, 2020
cbff72c
Merge remote-tracking branch 'upstream/v0.15-dev' into status-2
strophy Sep 3, 2020
b15c098
fix: check for testnet properly
strophy Sep 3, 2020
463eab5
Merge remote-tracking branch 'upstream/master' into status-2
strophy Nov 16, 2020
133068a
fix: refactor to use RPC
strophy Nov 16, 2020
3ff0fc0
fix: refactor tendermint calls
strophy Nov 17, 2020
4d228c0
fix: specify tendermint RPC protocol
strophy Nov 17, 2020
d29d922
fix: consistent terminology
strophy Nov 17, 2020
c6bd73e
feat: add arch
strophy Nov 19, 2020
3eb0e09
fix: round loadavg to 2 decimal places (for ARM)
strophy Nov 19, 2020
5040dc9
feat: initial refactor for different command names
strophy Nov 19, 2020
7019987
feat: add remaining core status output
strophy Nov 19, 2020
999806d
fix: tidy output for index, masternode & platform
strophy Nov 19, 2020
754bb97
feat: implement queue position
strophy Nov 20, 2020
3fea150
fix: queue and sentinel output
strophy Nov 20, 2020
ffc62d6
fix: linting
strophy Nov 20, 2020
4818d1c
fix: tenderdash sync progress & conditional checks
strophy Nov 20, 2020
e7867be
feat: apply colors
strophy Nov 21, 2020
de6736e
refactor: use object for insight urls
strophy Nov 21, 2020
50f54fa
docs: update command descriptions
strophy Nov 21, 2020
f71c010
refactor: use destructuring assignment
strophy Nov 22, 2020
130fd4d
feat: add time converter
strophy Nov 22, 2020
0779d76
refactor: don't mix await/then
strophy Nov 23, 2020
4b22b17
fix: use consistent colours
strophy Nov 23, 2020
4c34b2b
refactor: try more destructuring assignment
strophy Nov 23, 2020
a48413a
fix: run masternode checks only if masternode is ready
strophy Nov 24, 2020
961e590
fix: add some yellow statuses
strophy Nov 24, 2020
586e107
fix: don't use insight on local config
strophy Nov 24, 2020
27d06fa
refactor: util functions and destructuring assignment
strophy Nov 25, 2020
c71129d
fix: check platform explorer exists before query
strophy Dec 16, 2020
d586a52
fix: conditional checks for remote platform explorer
strophy Dec 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"lodash.get": "^4.4.2",
"lodash.merge": "^4.6.2",
"lodash.set": "^4.3.2",
"node-fetch": "^2.6.0",
"node-graceful": "^3.0.0",
"pretty-bytes": "^5.3.0",
"pretty-ms": "^7.0.0",
Expand Down
174 changes: 174 additions & 0 deletions src/commands/status/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
const { table } = require('table');
const fetch = require('node-fetch');
const chalk = require('chalk');

const BaseCommand = require('../../oclif/command/BaseCommand');
const CoreService = require('../../core/CoreService');

const ContainerIsNotPresentError = require('../../docker/errors/ContainerIsNotPresentError');

class CoreStatusCommand extends BaseCommand {
/**
* @param {Object} args
* @param {Object} flags
* @param {DockerCompose} dockerCompose
* @param {CoreService} coreService
* @param {Config} config
* @return {Promise<void>}
*/
async runWithDependencies(
args,
flags,
dockerCompose,
createRpcClient,
config,
) {
const rows = [];

const coreService = new CoreService(
createRpcClient(
{
port: config.get('core.rpc.port'),
user: config.get('core.rpc.user'),
pass: config.get('core.rpc.password'),
},
),
dockerCompose.docker.getContainer('core'),
);

const insightURLs = {
evonet: 'http://insight.evonet.networks.dash.org:3001/insight-api',
testnet: 'https://testnet-insight.dashevo.org/insight-api',
mainnet: 'https://insight.dash.org/insight-api',
};

// Collect data
const {
result: {
blocks: coreBlocks,
chain: coreChain,
difficulty: coreDifficulty,
headers: coreHeaders,
verificationprogress: coreVerificationProgress,
},
} = await coreService.getRpcClient().getBlockchainInfo();
const { result: networkInfo } = await coreService.getRpcClient().getNetworkInfo();
const { result: mnsyncStatus } = await coreService.getRpcClient().mnsync('status');
const { result: peerInfo } = await coreService.getRpcClient().getPeerInfo();
const latestVersionRes = await fetch('https://api.github.com/repos/dashpay/dash/releases/latest');
let {
tag_name: latestVersion,
} = await latestVersionRes.json();
latestVersion = latestVersion.substring(1);
const corePortStateRes = await fetch(`https://mnowatch.org/${config.options.core.p2p.port}/`);
let corePortState = await corePortStateRes.text();
let coreVersion = networkInfo.subversion.replace(/\/|\(.*?\)|Dash Core:/g, '');
let explorerBlockHeightRes;
let explorerBlockHeight;
if (insightURLs[config.options.network]) {
explorerBlockHeightRes = await fetch(`${insightURLs[config.options.network]}/status`);
({
info: {
blocks: explorerBlockHeight,
},
} = await explorerBlockHeightRes.json());
}
const sentinelVersion = (await dockerCompose.execCommand(
config.toEnvs(),
'sentinel',
'python bin/sentinel.py -v',
)).out.split('\n')[0].replace(/Dash Sentinel v/, '');
let sentinelState = (await dockerCompose.execCommand(
config.toEnvs(),
'sentinel',
'python bin/sentinel.py',
)).out.split('\n')[0];

// Determine status
let status;
try {
({
State: {
Status: status,
},
} = await dockerCompose.inspectService(config.toEnvs(), 'core'));
} catch (e) {
if (e instanceof ContainerIsNotPresentError) {
status = 'not started';
}
}
if (status === 'running' && mnsyncStatus.AssetName !== 'MASTERNODE_SYNC_FINISHED') {
status = `syncing ${(coreVerificationProgress * 100).toFixed(2)}%`;
}

// Apply colors
if (status === 'running') {
status = chalk.green(status);
} else if (status.startsWith('syncing')) {
status = chalk.yellow(status);
} else {
status = chalk.red(status);
}

if (coreVersion === latestVersion) {
coreVersion = chalk.green(coreVersion);
} else if (coreVersion.match(/\d+.\d+/)[0] === latestVersion.match(/\d+.\d+/)[0]) {
coreVersion = chalk.yellow(coreVersion);
} else {
strophy marked this conversation as resolved.
Show resolved Hide resolved
coreVersion = chalk.red(coreVersion);
}

if (corePortState === 'OPEN') {
corePortState = chalk.green(corePortState);
} else {
corePortState = chalk.red(corePortState);
}

let blocks;
if (coreBlocks === coreHeaders || coreBlocks >= explorerBlockHeight) {
blocks = chalk.green(coreBlocks);
} else if ((explorerBlockHeight - coreBlocks) < 3) {
blocks = chalk.yellow(coreBlocks);
} else {
blocks = chalk.red(coreBlocks);
}

if (sentinelState === '') {
sentinelState = chalk.green('No errors');
} else {
sentinelState = chalk.red(sentinelState);
}

// Build table
rows.push(['Version', coreVersion]);
rows.push(['Latest version', latestVersion]);
rows.push(['Network', coreChain]);
rows.push(['Status', status]);
rows.push(['Sync asset', mnsyncStatus.AssetName]);
rows.push(['Peer count', peerInfo.length]);
rows.push(['P2P service', `${config.options.externalIp}:${config.options.core.p2p.port}`]);
rows.push(['P2P port', `${config.options.core.p2p.port} ${corePortState}`]);
rows.push(['RPC service', `127.0.0.1:${config.options.core.rpc.port}`]);
rows.push(['Block height', blocks]);
rows.push(['Header height', coreHeaders]);
if (insightURLs[config.options.network]) {
rows.push(['Remote block height', explorerBlockHeight]);
}
rows.push(['Difficulty', coreDifficulty]);
rows.push(['Sentinel version', sentinelVersion]);
rows.push(['Sentinel status', (sentinelState)]);

const output = table(rows, { singleLine: true });

// eslint-disable-next-line no-console
console.log(output);
}
}

CoreStatusCommand.description = 'Show core status details';

CoreStatusCommand.flags = {
...BaseCommand.flags,
};

module.exports = CoreStatusCommand;
3 changes: 2 additions & 1 deletion src/commands/status/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class HostStatusCommand extends BaseCommand {
rows.push(['Hostname', os.hostname()]);
rows.push(['Uptime', prettyMs(os.uptime() * 1000)]);
rows.push(['Platform', os.platform()]);
rows.push(['Arch', os.arch()]);
rows.push(['Username', os.userInfo().username]);
rows.push(['Loadavg', os.loadavg()]);
rows.push(['Loadavg', os.loadavg().map((load) => load.toFixed(2))]);
rows.push(['Diskfree', 0]); // Waiting for feature: https://github.com/nodejs/node/pull/31351
rows.push(['Memory', `${prettyByte(os.totalmem())} / ${prettyByte(os.freemem())}`]);
rows.push(['CPUs', os.cpus().length]);
Expand Down
Loading