From: Willy Tarreau Date: Mon, 22 Oct 2012 21:17:18 +0000 (+0200) Subject: MEDIUM: cli: allow the stats socket to be bound to a specific set of processes X-Git-Tag: v1.5-dev13~124 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=35b7b168181feebcb9fa86aba7d1bfa58f193535;p=thirdparty%2Fhaproxy.git MEDIUM: cli: allow the stats socket to be bound to a specific set of processes Using "stats bind-process", it becomes possible to indicate to haproxy which process will get the incoming connections to the stats socket. It will also shut down the warning when nbproc > 1. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 4167d5e1ee..69f4591723 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -577,6 +577,15 @@ pidfile the "-p" command line argument. The file must be accessible to the user starting the process. See also "daemon". +stats bind-process [ all | odd | even | ] ... + Limits the stats socket to a certain set of processes numbers. By default the + stats socket is bound to all processes, causing a warning to be emitted when + nbproc is greater than 1 because there is no way to select the target process + when connecting. However, by using this setting, it becomes possible to pin + the stats socket to a specific set of processes, typically the first one. The + warning will automatically be disabled when this setting is used, whatever + the number of processes used. + stats socket [|] [param*] Binds a UNIX socket to or a TCPv4/v6 address to . Connections to this socket will return various statistics outputs and even diff --git a/src/cfgparse.c b/src/cfgparse.c index 3c77eede9d..3f43f581df 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -6646,8 +6646,8 @@ out_uri_auth_compat: /* Check multi-process mode compatibility */ if (global.nbproc > 1) { - if (global.stats_fe) { - Warning("stats socket will not work correctly in multi-process mode (nbproc > 1).\n"); + if (global.stats_fe && !global.stats_fe->bind_proc) { + Warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding using 'stats bind-process'.\n"); } } diff --git a/src/dumpstats.c b/src/dumpstats.c index fd7d422150..d0f0345db5 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -300,8 +300,38 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx } global.stats_fe->maxconn = maxconn; } + else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ + int cur_arg = 2; + unsigned int set = 0; + + while (*args[cur_arg]) { + int u; + if (strcmp(args[cur_arg], "all") == 0) { + set = 0; + break; + } + else if (strcmp(args[cur_arg], "odd") == 0) { + set |= 0x55555555; + } + else if (strcmp(args[cur_arg], "even") == 0) { + set |= 0xAAAAAAAA; + } + else { + u = str2uic(args[cur_arg]); + if (u < 1 || u > 32) { + memprintf(err, + "'%s %s' expects 'all', 'odd', 'even', or process numbers from 1 to 32.\n", + args[0], args[1]); + return -1; + } + set |= 1 << (u - 1); + } + cur_arg++; + } + global.stats_fe->bind_proc = set; + } else { - memprintf(err, "'%s' only supports 'socket', 'maxconn' and 'timeout' (got '%s')", args[0], args[1]); + memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); return -1; } return 0;