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.
This commit is contained in:
Willy Tarreau 2012-10-22 23:17:18 +02:00
parent 153c3cafd7
commit 35b7b16818
3 changed files with 42 additions and 3 deletions

View File

@ -577,6 +577,15 @@ pidfile <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 | <number 1-32> ] ...
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 [<address:port>|<path>] [param*]
Binds a UNIX socket to <path> or a TCPv4/v6 address to <address:port>.
Connections to this socket will return various statistics outputs and even

View File

@ -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");
}
}

View File

@ -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;