diff --git a/maxctrl/lib/common.js b/maxctrl/lib/common.js index 796fa1834..fce630d67 100644 --- a/maxctrl/lib/common.js +++ b/maxctrl/lib/common.js @@ -112,7 +112,7 @@ module.exports = function() { row = [] fields.forEach(function(p) { - var v = _.getPath(i, p[Object.keys(p)[0]], '') + var v = _.getPath(i, p.path, '') if (Array.isArray(v)) { v = v.join(', ') @@ -162,7 +162,7 @@ module.exports = function() { var header = [] fields.forEach(function(i) { - header.push(Object.keys(i)) + header.push(i.name) }) var table = getTable(header) @@ -188,7 +188,7 @@ module.exports = function() { var header = [] fields.forEach(function(i) { - header.push(Object.keys(i)) + header.push(i.name) }) var table = getTable(header) @@ -197,7 +197,7 @@ module.exports = function() { row = [] fields.forEach(function(p) { - var v = _.getPath(i, p[Object.keys(p)[0]], '') + var v = _.getPath(i, p[p.name], '') if (Array.isArray(v) && typeof(v[0]) != 'object') { v = v.join(', ') @@ -229,7 +229,7 @@ module.exports = function() { separator = '\n' var max_field_length = 0 fields.forEach(function (i) { - var k = Object.keys(i)[0] + var k = i.name if (k.length > max_field_length) { max_field_length = k.length } @@ -244,8 +244,8 @@ module.exports = function() { } fields.forEach(function(i) { - var k = Object.keys(i)[0] - var path = i[k] + var k = i.name + var path = i.path var v = _.getPath(data, path, '') if (Array.isArray(v) && typeof(v[0]) != 'object') { diff --git a/maxctrl/lib/list.js b/maxctrl/lib/list.js index f7a18594c..8789cd257 100644 --- a/maxctrl/lib/list.js +++ b/maxctrl/lib/list.js @@ -13,6 +13,200 @@ require('./common.js')() +const list_servers_fields = [ + { + name: 'Server', + path: 'id', + }, + { + name: 'Address', + path: 'attributes.parameters.address', + }, + { + name: 'Port', + path: 'attributes.parameters.port', + }, + { + name: 'Connections', + path: 'attributes.statistics.connections', + }, + { + name: 'State', + path: 'attributes.state', + }, + { + name: 'GTID', + path: 'attributes.gtid_current_pos', + } +] + +const list_services_fields = [ + { + name: 'Service', + path: 'id', + }, + { + name: 'Router', + path: 'attributes.router', + }, + { + name: 'Connections', + path: 'attributes.connections', + }, + { + name: 'Total Connections', + path: 'attributes.total_connections', + }, + { + name: 'Servers', + path: 'relationships.servers.data[].id', + } +] + +const list_listeners_fields = [ + { + name: 'Name', + path: 'id', + }, + { + name: 'Port', + path: 'attributes.parameters.port', + }, + { + name: 'Host', + path: 'attributes.parameters.host', + }, + { + name: 'State', + path: 'attributes.state', + } +] + +const list_monitors_fields = [ + { + name: 'Monitor', + path: 'id', + }, + { + name: 'State', + path: 'attributes.state', + }, + { + name: 'Servers', + path: 'relationships.servers.data[].id', + } +] + +const list_sessions_fields = [ + { + name: 'Id', + path: 'id', + }, + { + name: 'User', + path: 'attributes.user', + }, + { + name: 'Host', + path: 'attributes.remote', + }, + { + name: 'Connected', + path: 'attributes.connected', + }, + { + name: 'Idle', + path: 'attributes.idle', + }, + { + name: 'Service', + path: 'relationships.services.data[].id', + } +] + +const list_filters_fields = [ + { + name: 'Filter', + path: 'id', + }, + { + name: 'Service', + path: 'relationships.services.data[].id', + }, + { + name: 'Module', + path: 'attributes.module', + } +] + +const list_modules_fields = [ + { + name: 'Module', + path: 'id', + }, + { + name: 'Type', + path: 'attributes.module_type', + }, + { + name: 'Version', + path: 'attributes.version', + } +] + +const list_threads_fields = [ + { + name: 'Id', + path: 'id', + }, + { + name: 'Current FDs', + path: 'attributes.stats.current_descriptors', + }, + { + name: 'Total FDs', + path: 'attributes.stats.total_descriptors', + }, + { + name: 'Load (1s)', + path: 'attributes.stats.load.last_second', + }, + { + name: 'Load (1m)', + path: 'attributes.stats.load.last_minute', + }, + { + name: 'Load (1h)', + path: 'attributes.stats.load.last_hour', + } +] + +const list_users_fields = [ + { + name: 'Name', + path: 'id', + }, + { + name: 'Type', + path: 'type', + }, + { + name: 'Privileges', + path: 'attributes.account', + }, +] + +const list_commands_fields = [ + { + name: 'Module', + path: 'id', + }, + { + name: 'Commands', + path: 'attributes.commands[].id', + } +] + exports.command = 'list ' exports.desc = 'List objects' exports.handler = function() {} @@ -23,14 +217,6 @@ exports.builder = function(yargs) { .usage('Usage: list servers') }, function(argv) { maxctrl(argv, function(host) { - fields = [ - {'Server': 'id'}, - {'Address': 'attributes.parameters.address'}, - {'Port': 'attributes.parameters.port'}, - {'Connections': 'attributes.statistics.connections'}, - {'State': 'attributes.state'}, - {'GTID': 'attributes.gtid_current_pos'} - ] // First, get the list of all servers return getJson(host, 'servers') @@ -68,8 +254,8 @@ exports.builder = function(yargs) { } }) }) - .then(() => filterResource(res, fields)) - .then((res) => rawCollectionAsTable(res, fields)) + .then(() => filterResource(res, list_servers_fields)) + .then((res) => rawCollectionAsTable(res, list_servers_fields)) }) }) }) @@ -78,13 +264,7 @@ exports.builder = function(yargs) { .usage('Usage: list services') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'services',[ - {'Service': 'id'}, - {'Router': 'attributes.router'}, - {'Connections': 'attributes.connections'}, - {'Total Connections': 'attributes.total_connections'}, - {'Servers': 'relationships.servers.data[].id'} - ]) + return getCollection(host, 'services', list_services_fields) }) }) .command('listeners ', 'List listeners of a service', function(yargs) { @@ -92,12 +272,7 @@ exports.builder = function(yargs) { .usage('Usage: list listeners ') }, function(argv) { maxctrl(argv, function(host) { - return getSubCollection(host, 'services/' + argv.service, 'attributes.listeners', [ - {'Name': 'id'}, - {'Port': 'attributes.parameters.port'}, - {'Host': 'attributes.parameters.host'}, - {'State': 'attributes.state'} - ]) + return getSubCollection(host, 'services/' + argv.service, 'attributes.listeners', list_listeners_fields) }) }) .command('monitors', 'List monitors', function(yargs) { @@ -105,11 +280,7 @@ exports.builder = function(yargs) { .usage('Usage: list monitors') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'monitors', [ - {'Monitor': 'id'}, - {'State': 'attributes.state'}, - {'Servers': 'relationships.servers.data[].id'} - ]) + return getCollection(host, 'monitors', list_monitors_fields) }) }) .command('sessions', 'List sessions', function(yargs) { @@ -117,14 +288,7 @@ exports.builder = function(yargs) { .usage('Usage: list sessions') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'sessions',[ - {'Id': 'id'}, - {'User': 'attributes.user'}, - {'Host': 'attributes.remote'}, - {'Connected': 'attributes.connected'}, - {'Idle': 'attributes.idle'}, - {'Service': 'relationships.services.data[].id'} - ]) + return getCollection(host, 'sessions', list_sessions_fields) }) }) .command('filters', 'List filters', function(yargs) { @@ -132,11 +296,7 @@ exports.builder = function(yargs) { .usage('Usage: list filters') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'filters', [ - {'Filter': 'id'}, - {'Service': 'relationships.services.data[].id'}, - {'Module': 'attributes.module'} - ]) + return getCollection(host, 'filters', list_filters_fields) }) }) .command('modules', 'List loaded modules', function(yargs) { @@ -144,11 +304,7 @@ exports.builder = function(yargs) { .usage('Usage: list modules') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'maxscale/modules',[ - {'Module':'id'}, - {'Type':'attributes.module_type'}, - {'Version': 'attributes.version'} - ]) + return getCollection(host, 'maxscale/modules', list_modules_fields) }) }) .command('threads', 'List threads', function(yargs) { @@ -156,26 +312,16 @@ exports.builder = function(yargs) { .usage('Usage: list threads') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'maxscale/threads', [ - {'Id': 'id'}, - {'Current FDs': 'attributes.stats.current_descriptors'}, - {'Total FDs': 'attributes.stats.total_descriptors'}, - {'Load (1s)': 'attributes.stats.load.last_second'}, - {'Load (1m)': 'attributes.stats.load.last_minute'}, - {'Load (1h)': 'attributes.stats.load.last_hour'} - ]) + return getCollection(host, 'maxscale/threads', list_threads_fields) }) }) .command('users', 'List created users', function(yargs) { - return yargs.epilog('List network the users that can be used to connect to the MaxScale REST API as well as enabled local accounts.') + return yargs.epilog('List network the users that can be used to connect to the MaxScale REST API' + + ' as well as enabled local accounts.') .usage('Usage: list users') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'users',[ - {'Name':'id'}, - {'Type':'type'}, - {'Privileges':'attributes.account'}, - ]) + return getCollection(host, 'users', list_users_fields) }) }) .command('commands', 'List module commands', function(yargs) { @@ -183,10 +329,7 @@ exports.builder = function(yargs) { .usage('Usage: list commands') }, function(argv) { maxctrl(argv, function(host) { - return getCollection(host, 'maxscale/modules',[ - {'Module':'id'}, - {'Commands': 'attributes.commands[].id'} - ]) + return getCollection(host, 'maxscale/modules', list_commands_fields) }) }) .usage('Usage: list ') diff --git a/maxctrl/lib/show.js b/maxctrl/lib/show.js index 067af86b2..e643971a9 100644 --- a/maxctrl/lib/show.js +++ b/maxctrl/lib/show.js @@ -14,94 +14,360 @@ require('./common.js')() const server_fields = [ - {'Server': 'id'}, - {'Address': 'attributes.parameters.address'}, - {'Port': 'attributes.parameters.port'}, - {'State': 'attributes.state'}, - {'Last Event': 'attributes.last_event'}, - {'Triggered At': 'attributes.triggered_at'}, - {'Services': 'relationships.services.data[].id'}, - {'Monitors': 'relationships.monitors.data[].id'}, - {'Master ID': 'attributes.master_id'}, - {'Node ID': 'attributes.node_id'}, - {'Slave Server IDs': 'attributes.slaves'}, - {'Statistics': 'attributes.statistics'}, - {'Parameters': 'attributes.parameters'} + { + name: 'Server', + path: 'id', + }, + { + name: 'Address', + path: 'attributes.parameters.address', + }, + { + name: 'Port', + path: 'attributes.parameters.port', + }, + { + name: 'State', + path: 'attributes.state', + }, + { + name: 'Last Event', + path: 'attributes.last_event', + }, + { + name: 'Triggered At', + path: 'attributes.triggered_at', + }, + { + name: 'Services', + path: 'relationships.services.data[].id', + }, + { + name: 'Monitors', + path: 'relationships.monitors.data[].id', + }, + { + name: 'Master ID', + path: 'attributes.master_id', + }, + { + name: 'Node ID', + path: 'attributes.node_id', + }, + { + name: 'Slave Server IDs', + path: 'attributes.slaves', + }, + { + name: 'Statistics', + path: 'attributes.statistics', + }, + { + name: 'Parameters', + path: 'attributes.parameters', +} ] const service_fields = [ - {'Service': 'id'}, - {'Router': 'attributes.router'}, - {'State': 'attributes.state'}, - {'Started At': 'attributes.started'}, - {'Current Connections': 'attributes.connections'}, - {'Total Connections': 'attributes.total_connections'}, - {'Servers': 'relationships.servers.data[].id'}, - {'Parameters': 'attributes.parameters'}, - {'Router Diagnostics': 'attributes.router_diagnostics'} + { + name: 'Service', + path: 'id', + }, + { + name: 'Router', + path: 'attributes.router', + }, + { + name: 'State', + path: 'attributes.state', + }, + { + name: 'Started At', + path: 'attributes.started', + }, + { + name: 'Current Connections', + path: 'attributes.connections', + }, + { + name: 'Total Connections', + path: 'attributes.total_connections', + }, + { + name: 'Servers', + path: 'relationships.servers.data[].id', + }, + { + name: 'Parameters', + path: 'attributes.parameters', + }, + { + name: 'Router Diagnostics', + path: 'attributes.router_diagnostics', + } ] const monitor_fields = [ - {'Monitor': 'id'}, - {'State': 'attributes.state'}, - {'Servers': 'relationships.servers.data[].id'}, - {'Parameters': 'attributes.parameters'}, - {'Monitor Diagnostics': 'attributes.monitor_diagnostics'} + { + name: 'Monitor', + path: 'id', + }, + { + name: 'State', + path: 'attributes.state', + }, + { + name: 'Servers', + path: 'relationships.servers.data[].id', + }, + { + name: 'Parameters', + path: 'attributes.parameters', + }, + { + name: 'Monitor Diagnostics', + path: 'attributes.monitor_diagnostics',} ] const session_fields = [ - {'Id': 'id'}, - {'Service': 'relationships.services.data[].id'}, - {'State': 'attributes.state'}, - {'User': 'attributes.user'}, - {'Host': 'attributes.remote'}, - {'Connected': 'attributes.connected'}, - {'Idle': 'attributes.idle'}, - {'Connections': 'attributes.connections[].server'}, - {'Connection IDs': 'attributes.connections[].protocol_diagnostics.connection_id'}, - {'Queries': 'attributes.queries[].statement'}, - {'Log': 'attributes.log'} + { + name: 'Id', + path: 'id', + }, + { + name: 'Service', + path: 'relationships.services.data[].id', + }, + { + name: 'State', + path: 'attributes.state', + }, + { + name: 'User', + path: 'attributes.user', + }, + { + name: 'Host', + path: 'attributes.remote', + }, + { + name: 'Connected', + path: 'attributes.connected', + }, + { + name: 'Idle', + path: 'attributes.idle', + }, + { + name: 'Connections', + path: 'attributes.connections[].server', + }, + { + name: 'Connection IDs', + path: 'attributes.connections[].protocol_diagnostics.connection_id', + }, + { + name: 'Queries', + path: 'attributes.queries[].statement', + }, + { + name: 'Log', + path: 'attributes.log', +} ] const filter_fields = [ - {'Filter': 'id'}, - {'Module': 'attributes.module'}, - {'Services': 'relationships.services.data[].id'}, - {'Parameters': 'attributes.parameters'} + { + name: 'Filter', + path: 'id', + }, + { + name: 'Module', + path: 'attributes.module', + }, + { + name: 'Services', + path: 'relationships.services.data[].id', + }, + { + name: 'Parameters', + path: 'attributes.parameters', + } ] const module_fields = [ - {'Module': 'id'}, - {'Type': 'attributes.module_type'}, - {'Version': 'attributes.version'}, - {'Maturity': 'attributes.maturity'}, - {'Description': 'attributes.description'}, - {'Parameters': 'attributes.parameters'}, - {'Commands': 'attributes.commands'} + { + name: 'Module', + path: 'id', + }, + { + name: 'Type', + path: 'attributes.module_type', + }, + { + name: 'Version', + path: 'attributes.version', + }, + { + name: 'Maturity', + path: 'attributes.maturity', + }, + { + name: 'Description', + path: 'attributes.description', + }, + { + name: 'Parameters', + path: 'attributes.parameters', + }, + { + name: 'Commands', + path: 'attributes.commands', + } ] const thread_fields = [ - {'Id': 'id'}, - {'Accepts': 'attributes.stats.accepts'}, - {'Reads': 'attributes.stats.reads'}, - {'Writes': 'attributes.stats.writes'}, - {'Hangups': 'attributes.stats.hangups'}, - {'Errors': 'attributes.stats.errors'}, - {'Blocking polls': 'attributes.stats.blocking_polls'}, - {'Avg event queue length': 'attributes.stats.avg_event_queue_length'}, - {'Max event queue length': 'attributes.stats.max_event_queue_length'}, - {'Max exec time': 'attributes.stats.max_exec_time'}, - {'Max queue time': 'attributes.stats.max_queue_time'}, - {'Current FDs': 'attributes.stats.current_descriptors'}, - {'Total FDs': 'attributes.stats.total_descriptors'}, - {'Load (1s)': 'attributes.stats.load.last_second'}, - {'Load (1m)': 'attributes.stats.load.last_minute'}, - {'Load (1h)': 'attributes.stats.load.last_hour'}, - {'QC cache size': 'attributes.stats.query_classifier_cache.size'}, - {'QC cache inserts': 'attributes.stats.query_classifier_cache.inserts'}, - {'QC cache hits': 'attributes.stats.query_classifier_cache.hits'}, - {'QC cache misses': 'attributes.stats.query_classifier_cache.misses'}, - {'QC cache evictions': 'attributes.stats.query_classifier_cache.evictions'}, + { + name: 'Id', + path: 'id', + }, + { + name: 'Accepts', + path: 'attributes.stats.accepts', + }, + { + name: 'Reads', + path: 'attributes.stats.reads', + }, + { + name: 'Writes', + path: 'attributes.stats.writes', + }, + { + name: 'Hangups', + path: 'attributes.stats.hangups', + }, + { + name: 'Errors', + path: 'attributes.stats.errors', + }, + { + name: 'Blocking polls', + path: 'attributes.stats.blocking_polls', + }, + { + name: 'Avg event queue length', + path: 'attributes.stats.avg_event_queue_length', + }, + { + name: 'Max event queue length', + path: 'attributes.stats.max_event_queue_length', + }, + { + name: 'Max exec time', + path: 'attributes.stats.max_exec_time', + }, + { + name: 'Max queue time', + path: 'attributes.stats.max_queue_time', + }, + { + name: 'Current FDs', + path: 'attributes.stats.current_descriptors', + }, + { + name: 'Total FDs', + path: 'attributes.stats.total_descriptors', + }, + { + name: 'Load (1s)', + path: 'attributes.stats.load.last_second', + }, + { + name: 'Load (1m)', + path: 'attributes.stats.load.last_minute', + }, + { + name: 'Load (1h)', + path: 'attributes.stats.load.last_hour', + }, + { + name: 'QC cache size', + path: 'attributes.stats.query_classifier_cache.size', + }, + { + name: 'QC cache inserts', + path: 'attributes.stats.query_classifier_cache.inserts', + }, + { + name: 'QC cache hits', + path: 'attributes.stats.query_classifier_cache.hits', + }, + { + name: 'QC cache misses', + path: 'attributes.stats.query_classifier_cache.misses', + }, + { + name: 'QC cache evictions', + path: 'attributes.stats.query_classifier_cache.evictions', + }, +] + +const show_maxscale_fields = [ + { + name: 'Version', + path: 'attributes.version', + }, + { + name: 'Commit', + path: 'attributes.commit', + }, + { + name: 'Started At', + path: 'attributes.started_at', + }, + { + name: 'Activated At', + path: 'attributes.activated_at', + }, + { + name: 'Uptime', + path: 'attributes.uptime', + }, + { + name: 'Parameters', + path: 'attributes.parameters', + } +] + +const show_logging_fields = [ + { + name: 'Current Log File', + path: 'attributes.log_file', + }, + { + name: 'Enabled Log Levels', + path: 'attributes.log_priorities', + }, + { + name: 'Parameters', + path: 'attributes.parameters', + } +] + +const show_commands_fields = [ + { + name: 'Command', + path: 'id', + }, + { + name: 'Parameters', + path: 'attributes.parameters[].type', + }, + { + name: 'Descriptions', + path: 'attributes.parameters[].description', + } ] exports.command = 'show ' @@ -228,14 +494,7 @@ exports.builder = function(yargs) { .usage('Usage: show maxscale') }, function(argv) { maxctrl(argv, function(host) { - return getResource(host, 'maxscale', [ - {'Version': 'attributes.version'}, - {'Commit': 'attributes.commit'}, - {'Started At': 'attributes.started_at'}, - {'Activated At': 'attributes.activated_at'}, - {'Uptime': 'attributes.uptime'}, - {'Parameters': 'attributes.parameters'} - ]) + return getResource(host, 'maxscale', show_maxscale_fields) }) }) .command('thread ', 'Show thread', function(yargs) { @@ -260,11 +519,7 @@ exports.builder = function(yargs) { .usage('Usage: show logging') }, function(argv) { maxctrl(argv, function(host) { - return getResource(host, 'maxscale/logs', [ - {'Current Log File': 'attributes.log_file'}, - {'Enabled Log Levels': 'attributes.log_priorities'}, - {'Parameters': 'attributes.parameters'} - ]) + return getResource(host, 'maxscale/logs', show_logging_fields) }) }) .command('commands ', 'Show module commands of a module', function(yargs) { @@ -273,11 +528,8 @@ exports.builder = function(yargs) { .usage('Usage: show commands ') }, function(argv) { maxctrl(argv, function(host) { - return getSubCollection(host, 'maxscale/modules/' + argv.module, 'attributes.commands', [ - {'Command': 'id'}, - {'Parameters': 'attributes.parameters[].type'}, - {'Descriptions': 'attributes.parameters[].description'} - ]) + return getSubCollection(host, 'maxscale/modules/' + argv.module, 'attributes.commands', + show_commands_fields) }) }) .usage('Usage: show ')