MINOR: mworker: add the HAProxy version in "show proc"

Displays the HAProxy version so you can compare the version of old
processes and new ones.
This commit is contained in:
William Lallemand 2019-06-12 19:11:33 +02:00 committed by William Lallemand
parent e8669fc9db
commit 1dc6963086
4 changed files with 21 additions and 12 deletions

View File

@ -2612,13 +2612,13 @@ processes:
Example: Example:
$ echo 'show proc' | socat /var/run/haproxy-master.sock - $ echo 'show proc' | socat /var/run/haproxy-master.sock -
#<PID> <type> <relative PID> <reloads> <uptime> #<PID> <type> <relative PID> <reloads> <uptime> <version>
1162 master 0 5 0d 00h02m07s 1162 master 0 5 0d00h02m07s 2.0-dev7-0124c9-7
# workers # workers
1271 worker 1 0 0d 00h00m00s 1271 worker 1 0 0d00h00m00s 2.0-dev7-0124c9-7
1272 worker 2 0 0d 00h00m00s 1272 worker 2 0 0d00h00m00s 2.0-dev7-0124c9-7
# old workers # old workers
1233 worker [was: 1] 3 0d 00h00m43s 1233 worker [was: 1] 3 0d00h00m43s 2.0-dev3-6019f6-289
In this example, the master has been reloaded 5 times but one of the old In this example, the master has been reloaded 5 times but one of the old

View File

@ -208,6 +208,7 @@ struct mworker_proc {
char *id; char *id;
char **command; char **command;
char *path; char *path;
char *version;
int ipc_fd[2]; /* 0 is master side, 1 is worker side */ int ipc_fd[2]; /* 0 is master side, 1 is worker side */
int relative_pid; int relative_pid;
int reloads; int reloads;

View File

@ -3039,6 +3039,7 @@ int main(int argc, char **argv)
child->reloads == 0 && child->options & PROC_O_TYPE_WORKER) { child->reloads == 0 && child->options & PROC_O_TYPE_WORKER) {
child->timestamp = now.tv_sec; child->timestamp = now.tv_sec;
child->pid = ret; child->pid = ret;
child->version = strdup(haproxy_version);
break; break;
} }
} }

View File

@ -20,6 +20,7 @@
#include <common/cfgparse.h> #include <common/cfgparse.h>
#include <common/initcall.h> #include <common/initcall.h>
#include <common/mini-clist.h> #include <common/mini-clist.h>
#include <common/version.h>
#include <types/cli.h> #include <types/cli.h>
#include <types/global.h> #include <types/global.h>
@ -121,7 +122,7 @@ void mworker_proc_list_to_env()
type = 'w'; type = 'w';
if (child->pid > -1) if (child->pid > -1)
memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d;id=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp, child->id ? child->id : ""); memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp, child->id ? child->id : "", child->version);
} }
if (msg) if (msg)
setenv("HAPROXY_PROCESSES", msg, 1); setenv("HAPROXY_PROCESSES", msg, 1);
@ -177,6 +178,8 @@ void mworker_env_to_proc_list()
child->timestamp = atoi(subtoken+10); child->timestamp = atoi(subtoken+10);
} else if (strncmp(subtoken, "id=", 3) == 0) { } else if (strncmp(subtoken, "id=", 3) == 0) {
child->id = strdup(subtoken+3); child->id = strdup(subtoken+3);
} else if (strncmp(subtoken, "version=", 8) == 0) {
child->version = strdup(subtoken+8);
} }
} }
if (child->pid) { if (child->pid) {
@ -444,9 +447,9 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
chunk_reset(&trash); chunk_reset(&trash);
chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>"); chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>", "<version>");
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime); chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime, haproxy_version);
free(uptime); free(uptime);
uptime = NULL; uptime = NULL;
@ -464,7 +467,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
continue; continue;
} }
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime); chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime, child->version);
free(uptime); free(uptime);
uptime = NULL; uptime = NULL;
} }
@ -484,7 +487,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
if (child->options & PROC_O_LEAVING) { if (child->options & PROC_O_LEAVING) {
memprintf(&msg, "[was: %u]", child->relative_pid); memprintf(&msg, "[was: %u]", child->relative_pid);
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, "worker", msg, child->reloads, uptime); chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, "worker", msg, child->reloads, uptime, child->version);
free(uptime); free(uptime);
uptime = NULL; uptime = NULL;
} }
@ -506,7 +509,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
continue; continue;
} }
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime); chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-");
free(uptime); free(uptime);
uptime = NULL; uptime = NULL;
} }
@ -521,7 +524,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
if (child->options & PROC_O_LEAVING) { if (child->options & PROC_O_LEAVING) {
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime); chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-");
free(uptime); free(uptime);
uptime = NULL; uptime = NULL;
} }
@ -599,6 +602,10 @@ void mworker_free_child(struct mworker_proc *child)
free(child->id); free(child->id);
child->id = NULL; child->id = NULL;
} }
if (child->version) {
free(child->version);
child->version = NULL;
}
free(child); free(child);
} }