From 5d6037303ba40c104ae223c943215dd14a8fdd3e Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 7 Feb 2019 14:33:47 +0900 Subject: [PATCH] "daemon status": display node priority GitHub #541. --- doc/repmgr-daemon-status.sgml | 42 ++++++++++++++++++++--------------- repmgr-action-daemon.c | 26 +++++++++++++++++----- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/doc/repmgr-daemon-status.sgml b/doc/repmgr-daemon-status.sgml index 82adec3a..aa78cf42 100644 --- a/doc/repmgr-daemon-status.sgml +++ b/doc/repmgr-daemon-status.sgml @@ -49,31 +49,31 @@ repmgrd running normally on all nodes: $ repmgr -f /etc/repmgr.conf daemon status - ID | Name | Role | Status | repmgrd | PID | Paused? -----+-------+---------+---------+---------+------+--------- - 1 | node1 | primary | running | running | 7851 | no - 2 | node2 | standby | running | running | 7889 | no - 3 | node3 | standby | running | running | 7918 | no + ID | Name | Role | Priority | Status | repmgrd | PID | Paused? +----+-------+---------+----------+---------+---------+------+--------- + 1 | node1 | primary | 100 | running | running | 5722 | no + 2 | node2 | standby | 100 | running | running | 5731 | no + 3 | node3 | standby | 100 | running | running | 5779 | no repmgrd paused on all nodes (using ): $ repmgr -f /etc/repmgr.conf daemon status - ID | Name | Role | Status | repmgrd | PID | Paused? -----+-------+---------+---------+---------+------+--------- - 1 | node1 | primary | running | running | 7851 | yes - 2 | node2 | standby | running | running | 7889 | yes - 3 | node3 | standby | running | running | 7918 | yes + ID | Name | Role | Priority | Status | repmgrd | PID | Paused? +----+-------+---------+----------+---------+---------+------+--------- + 1 | node1 | primary | 100 | running | running | 5722 | yes + 2 | node2 | standby | 100 | running | running | 5731 | yes + 3 | node3 | standby | 100 | running | running | 5779 | yes repmgrd not running on one node: $ repmgr -f /etc/repmgr.conf daemon status - ID | Name | Role | Status | repmgrd | PID | Paused? -----+-------+---------+---------+-------------+------+--------- - 1 | node1 | primary | running | running | 7851 | yes - 2 | node2 | standby | running | not running | n/a | n/a - 3 | node3 | standby | running | running | 7918 | yes + ID | Name | Role | Priority | Status | repmgrd | PID | Paused? +----+-------+---------+----------+---------+-------------+------+--------- + 1 | node1 | primary | 100 | running | running | 5722 | yes + 2 | node2 | standby | 100 | running | not running | n/a | n/a + 3 | node3 | standby | 100 | running | running | 5779 | yes @@ -92,9 +92,9 @@ parsing by scripts, e.g.: $ repmgr -f /etc/repmgr.conf daemon status --csv - 1,node1,primary,1,1,10204,1 - 2,node2,standby,1,0,-1,1 - 3,node3,standby,1,1,10225,1 + 1,node1,primary,1,1,5722,1,100 + 2,node2,standby,1,0,-1,1,100 + 3,node3,standby,1,1,5779,1,100 The columns have following meanings: @@ -141,6 +141,12 @@ + + + repmgrd priority + + + diff --git a/repmgr-action-daemon.c b/repmgr-action-daemon.c index bb724ef0..882b775e 100644 --- a/repmgr-action-daemon.c +++ b/repmgr-action-daemon.c @@ -43,13 +43,14 @@ typedef enum STATUS_ID = 0, STATUS_NAME, STATUS_ROLE, + STATUS_PRIORITY, STATUS_PG, STATUS_RUNNING, STATUS_PID, STATUS_PAUSED } StatusHeader; -#define STATUS_HEADER_COUNT 7 +#define STATUS_HEADER_COUNT 8 struct ColHeader headers_status[STATUS_HEADER_COUNT]; @@ -89,6 +90,12 @@ do_daemon_status(void) strncpy(headers_status[STATUS_ID].title, _("ID"), MAXLEN); strncpy(headers_status[STATUS_NAME].title, _("Name"), MAXLEN); strncpy(headers_status[STATUS_ROLE].title, _("Role"), MAXLEN); + + if (runtime_options.compact == true) + strncpy(headers_status[STATUS_PRIORITY].title, _("Prio."), MAXLEN); + else + strncpy(headers_status[STATUS_PRIORITY].title, _("Priority"), MAXLEN); + strncpy(headers_status[STATUS_PG].title, _("Status"), MAXLEN); strncpy(headers_status[STATUS_RUNNING].title, _("repmgrd"), MAXLEN); strncpy(headers_status[STATUS_PID].title, _("PID"), MAXLEN); @@ -105,6 +112,7 @@ do_daemon_status(void) for (cell = nodes.head; cell; cell = cell->next) { int j; + PQExpBufferData buf; repmgrd_info[i] = pg_malloc0(sizeof(RepmgrdInfo)); repmgrd_info[i]->node_id = cell->node_info->node_id; @@ -191,6 +199,12 @@ do_daemon_status(void) headers_status[STATUS_NAME].cur_length = strlen(cell->node_info->node_name); headers_status[STATUS_ROLE].cur_length = strlen(get_node_type_string(cell->node_info->type)); + + initPQExpBuffer(&buf); + appendPQExpBuffer(&buf, "%i", cell->node_info->priority); + headers_status[STATUS_PRIORITY].cur_length = strlen(buf.data); + termPQExpBuffer(&buf); + headers_status[STATUS_PID].cur_length = strlen(repmgrd_info[i]->pid_text); headers_status[STATUS_RUNNING].cur_length = strlen(repmgrd_info[i]->repmgrd_running); headers_status[STATUS_PG].cur_length = strlen(repmgrd_info[i]->pg_running_text); @@ -218,20 +232,22 @@ do_daemon_status(void) { if (runtime_options.output_mode == OM_CSV) { - printf("%i,%s,%s,%i,%i,%i,%i\n", + printf("%i,%s,%s,%i,%i,%i,%i,%i\n", cell->node_info->node_id, cell->node_info->node_name, get_node_type_string(cell->node_info->type), repmgrd_info[i]->pg_running ? 1 : 0, repmgrd_info[i]->running ? 1 : 0, repmgrd_info[i]->pid, - repmgrd_info[i]->paused ? 1 : 0); + repmgrd_info[i]->paused ? 1 : 0, + cell->node_info->priority); } else { printf(" %-*i ", headers_status[STATUS_ID].max_length, cell->node_info->node_id); printf("| %-*s ", headers_status[STATUS_NAME].max_length, cell->node_info->node_name); printf("| %-*s ", headers_status[STATUS_ROLE].max_length, get_node_type_string(cell->node_info->type)); + printf("| %-*i ", headers_status[STATUS_PRIORITY].max_length, cell->node_info->priority); printf("| %-*s ", headers_status[STATUS_PG].max_length, repmgrd_info[i]->pg_running_text); printf("| %-*s ", headers_status[STATUS_RUNNING].max_length, repmgrd_info[i]->repmgrd_running); @@ -245,11 +261,11 @@ do_daemon_status(void) printf("\n"); } - free(repmgrd_info[i]); + pfree(repmgrd_info[i]); i++; } - free(repmgrd_info); + pfree(repmgrd_info); /* emit any warnings */