]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] make the global stats socket part of a frontend
authorWilly Tarreau <w@1wt.eu>
Sun, 16 Aug 2009 15:41:45 +0000 (17:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 16 Aug 2009 17:31:51 +0000 (19:31 +0200)
Creating a frontend for the global stats socket will help merge
unix sockets management with the other socket management. Since
frontends are huge structs, we only allocate it if required.

include/types/global.h
src/dumpstats.c
src/haproxy.c
src/proto_uxst.c

index 5c6e982175d5ee0303b029cb94331b19bd602423..aefee3226093466b63aff81675903b8372530954 100644 (file)
@@ -27,6 +27,7 @@
 #include <common/config.h>
 #include <types/log.h>
 #include <types/protocols.h>
+#include <types/proxy.h>
 #include <types/task.h>
 
 /* modes of operation (global.mode) */
@@ -80,7 +81,7 @@ struct global {
                int recv_enough;   /* how many input bytes at once are "enough" */
        } tune;
        struct listener stats_sock; /* unix socket listener for statistics */
-       int stats_timeout;          /* in ticks */
+       struct proxy *stats_fe;     /* the frontend holding the stats settings */
 };
 
 extern struct global global;
index d7c5110df780d604306bca389dcc1553e020e056..0615366824778825c0796e18beaa52a229d0341f 100644 (file)
@@ -44,6 +44,7 @@
 #include <proto/freq_ctr.h>
 #include <proto/pipe.h>
 #include <proto/proto_uxst.h>
+#include <proto/proxy.h>
 #include <proto/session.h>
 #include <proto/server.h>
 #include <proto/stream_interface.h>
@@ -78,12 +79,42 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
                su.sun_path[sizeof(su.sun_path) - 1] = 0;
                memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
 
+               if (!global.stats_fe) {
+                       if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
+                               snprintf(err, errlen, "out of memory");
+                               return -1;
+                       }
+
+                       LIST_INIT(&global.stats_fe->pendconns);
+                       LIST_INIT(&global.stats_fe->acl);
+                       LIST_INIT(&global.stats_fe->block_cond);
+                       LIST_INIT(&global.stats_fe->redirect_rules);
+                       LIST_INIT(&global.stats_fe->mon_fail_cond);
+                       LIST_INIT(&global.stats_fe->switching_rules);
+                       LIST_INIT(&global.stats_fe->tcp_req.inspect_rules);
+
+                       /* Timeouts are defined as -1, so we cannot use the zeroed area
+                        * as a default value.
+                        */
+                       proxy_reset_timeouts(global.stats_fe);
+
+                       global.stats_fe->last_change = now.tv_sec;
+                       global.stats_fe->id = strdup("GLOBAL");
+                       global.stats_fe->cap = PR_CAP_FE;
+               }
+
                global.stats_sock.state = LI_INIT;
                global.stats_sock.options = LI_O_NONE;
                global.stats_sock.accept = uxst_event_accept;
                global.stats_sock.handler = uxst_process_session;
                global.stats_sock.analysers = AN_REQ_UNIX_STATS;
-               global.stats_sock.private = NULL;
+               global.stats_sock.private = global.stats_fe; /* must point to the frontend */
+
+               global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
+               global.stats_sock.timeout = &global.stats_fe->timeout.client;
+
+               global.stats_sock.next  = global.stats_fe->listen;
+               global.stats_fe->listen = &global.stats_sock;
 
                cur_arg = 2;
                while (*args[cur_arg]) {
@@ -143,7 +174,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
                        snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
                        return -1;
                }
-               global.stats_timeout = MS_TO_TICKS(timeout);
+               global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
        }
        else if (!strcmp(args[0], "maxconn")) {
                int maxconn = atol(args[1]);
index a592d46f86f51694f95d8507dda65a6b3d38f468..09f828809df51c93ae7ff838cd668758469d6b87 100644 (file)
@@ -113,9 +113,7 @@ struct global global = {
        logfac2 : -1,
        loglev1 : 7, /* max syslog level : debug */
        loglev2 : 7,
-       .stats_timeout = MS_TO_TICKS(10000), /* stats timeout = 10 seconds */
        .stats_sock = {
-               .timeout = &global.stats_timeout,
                .maxconn = 10, /* 10 concurrent stats connections */
                .perm = {
                         .ux = {
index 8c1f2c56ac48cb7029afec505af938ea6474e904..742d1160b22aa356e3e1106ff37baca685669d9a 100644 (file)
@@ -450,8 +450,7 @@ int uxst_event_accept(int fd) {
 
                s->task = t;
                s->listener = l;
-               s->fe = NULL;
-               s->be = NULL;
+               s->fe = s->be = l->private;
 
                s->ana_state = 0;
                s->req = s->rep = NULL; /* will be allocated later */