From fcc28c1b6e3a4bd0ab67847e9cb9c75ea27faf7b Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 25 Jan 2019 13:42:06 +0100 Subject: [PATCH] Show information about timelines in patronictl list This information will help to detect stale replicas In addition to that Host will include ':{port}' if the port value is not default or more than one member running on the same host. Fixes: https://github.com/zalando/patroni/issues/942 --- patroni/ctl.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/patroni/ctl.py b/patroni/ctl.py index 32ee99b9..7a2fc2d8 100644 --- a/patroni/ctl.py +++ b/patroni/ctl.py @@ -180,7 +180,7 @@ def print_output(columns, rows=None, alignment=None, fmt='pretty', header=True, if fmt == 'tsv': if columns is not None and header: - click.echo(delimiter.join(columns) + '\n') + click.echo(delimiter.join(columns)) for r in rows: c = [str(c) for c in r] @@ -716,6 +716,10 @@ def output_members(cluster, name, extended=False, fmt='pretty'): has_scheduled_restarts = any(m.data.get('scheduled_restart') for m in cluster.members) has_pending_restarts = any(m.data.get('pending_restart') for m in cluster.members) + # Show Host as 'host:port' if somebody is running on non-standard port or two nodes are running on the same host + append_port = any(str(m.conn_kwargs()['port']) != '5432' for m in cluster.members) or\ + len(set(m.conn_kwargs()['host'] for m in cluster.members)) < len(cluster.members) + for m in cluster.members: logging.debug(m) @@ -732,7 +736,11 @@ def output_members(cluster, name, extended=False, fmt='pretty'): elif xlog_location_cluster >= xlog_location: lag = round((xlog_location_cluster - xlog_location)/1024/1024) - row = [name, m.name, m.conn_kwargs()['host'], role, m.data.get('state', ''), lag] + host = m.conn_kwargs()['host'] + if append_port: + host += ':{0}'.format(m.conn_kwargs()['port']) + + row = [name, m.name, host, role, m.data.get('state', ''), m.data.get('timeline', ''), lag] if extended or has_pending_restarts: row.append('*' if m.data.get('pending_restart') else '') @@ -749,8 +757,8 @@ def output_members(cluster, name, extended=False, fmt='pretty'): rows.append(row) - columns = ['Cluster', 'Member', 'Host', 'Role', 'State', 'Lag in MB'] - alignment = {'Lag in MB': 'r'} + columns = ['Cluster', 'Member', 'Host', 'Role', 'State', 'TL', 'Lag in MB'] + alignment = {'Lag in MB': 'r', 'TL': 'r'} if extended or has_pending_restarts: columns.append('Pending restart')