]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cli: allow the stats socket to be bound to a specific set of processes
authorWilly Tarreau <w@1wt.eu>
Mon, 22 Oct 2012 21:17:18 +0000 (23:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 22 Oct 2012 21:17:18 +0000 (23:17 +0200)
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.

doc/configuration.txt
src/cfgparse.c
src/dumpstats.c

index 4167d5e1eec9c0321e50a284e3d5939eb6ab5752..69f4591723ed7fd74d73bef0d2633a3071fe6bbe 100644 (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
index 3c77eede9dda2c06deb7a84db771bc3d28c35d75..3f43f581dfe1a38ffa068ca67552d6ba8cffc53a 100644 (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");
                }
        }
 
index fd7d4221505ed04388ebcb61b0b46afd2dc372c2..d0f0345db5ff9c5f7165a68e250dcf2154e956ae 100644 (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;