]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: counters: move from 3 types to 2 types
authorWilly Tarreau <w@1wt.eu>
Fri, 25 Nov 2016 13:44:52 +0000 (14:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 25 Nov 2016 14:03:12 +0000 (15:03 +0100)
We used to have 3 types of counters with a huge overlap :
  - listener counters : stats collected for each bind line
  - proxy counters : union of the frontend and backend counters
  - server counters : stats collected per server

It happens that quite a good part was common between listeners and
proxies due to the frontend counters being updated at the two locations,
and that similarly the server and proxy counters were overlapping and
being updated together.

This patch cleans this up to propose only two types of counters :
  - fe_counters: used by frontends and listeners, related to
    incoming connections activity
  - be_counters: used by backends and servers, related to outgoing
    connections activity

This allowed to remove some non-sensical counters from both parts. For
frontends, the following entries were removed :

  cum_lbconn, last_sess, nbpend_max, failed_conns, failed_resp,
  retries, redispatches, q_time, c_time, d_time, t_time

For backends, this ones was removed : intercepted_req.

While doing this it was discovered that we used to incorrectly report
intercepted_req for backends in the HTML stats, which was always zero
since it's never updated.

Also it revealed a few inconsistencies (which were not fixed as they
are harmless). For example, backends count connections (cum_conn)
instead of sessions while servers count sessions and not connections.

Over the long term, some extra cleanups may be performed by having
some counters update functions touching both the server and backend
at the same time, as well as both the frontend and listener, to
ensure that all sides have all their stats properly filled. The stats
dump will also be able to factor the dump functions by counter types.

include/types/counters.h
include/types/listener.h
include/types/proxy.h
include/types/server.h
src/cfgparse.c
src/stats.c

index 3e62763f867989a6a76c2ff6b8f08a5f255b3816..06ce617280d1d5d327fb19add05a76069c29d344 100644 (file)
 #ifndef _TYPES_COUNTERS_H
 #define _TYPES_COUNTERS_H
 
-/* maybe later we might thing about having a different struct for FE and BE */
-struct pxcounters {
+/* counters used by listeners and frontends */
+struct fe_counters {
        unsigned int conn_max;                  /* max # of active sessions */
        long long    cum_conn;                  /* cumulated number of received connections */
        long long    cum_sess;                  /* cumulated number of accepted connections */
-       long long  cum_lbconn;                  /* cumulated number of sessions processed by load balancing (BE only) */
-       unsigned long last_sess;                /* last session time */
 
        unsigned int cps_max;                   /* maximum of new connections received per second */
        unsigned int sps_max;                   /* maximum of new connections accepted per second (sessions) */
-       unsigned int nbpend_max;                /* max number of pending connections with no server assigned yet (BE only) */
 
        long long bytes_in;                     /* number of bytes transferred from the client to the server */
        long long bytes_out;                    /* number of bytes transferred from the server to the client */
@@ -42,22 +39,16 @@ struct pxcounters {
        long long comp_out;                     /* output bytes emitted by the compressor */
        long long comp_byp;                     /* input bytes that bypassed the compressor (cpu/ram/bw limitation) */
 
-       long long denied_req;                   /* blocked requests/responses because of security concerns */
-       long long denied_resp;                  /* blocked requests/responses because of security concerns */
+       long long denied_req;                   /* blocked requests because of security concerns */
+       long long denied_resp;                  /* blocked responses because of security concerns */
        long long failed_req;                   /* failed requests (eg: invalid or timeout) */
        long long denied_conn;                  /* denied connection requests (tcp-req-conn rules) */
        long long denied_sess;                  /* denied session requests (tcp-req-sess rules) */
 
-       long long failed_conns;                 /* failed connect() attempts (BE only) */
-       long long failed_resp;                  /* failed responses (BE only) */
        long long cli_aborts;                   /* aborted responses during DATA phase caused by the client */
        long long srv_aborts;                   /* aborted responses during DATA phase caused by the server */
-       long long retries;                      /* retried and redispatched connections (BE only) */
-       long long redispatches;                 /* retried and redispatched connections (BE only) */
        long long intercepted_req;              /* number of monitoring or stats requests intercepted by the frontend */
 
-       unsigned int q_time, c_time, d_time, t_time; /* sums of conn_time, queue_time, data_time, total_time */
-
        union {
                struct {
                        long long cum_req;      /* cumulated number of processed HTTP requests */
@@ -68,48 +59,50 @@ struct pxcounters {
        } p;                                    /* protocol-specific stats */
 };
 
-struct licounters {
-       unsigned int conn_max;                  /* max # of active listener sessions */
-
-       long long cum_conn;                     /* cumulated number of received connections */
-       long long cum_sess;                     /* cumulated number of accepted sessions */
-
-       long long bytes_in;                     /* number of bytes transferred from the client to the server */
-       long long bytes_out;                    /* number of bytes transferred from the server to the client */
-
-       long long denied_req, denied_resp;      /* blocked requests/responses because of security concerns */
-       long long failed_req;                   /* failed requests (eg: invalid or timeout) */
-       long long denied_conn;                  /* denied connection requests (tcp-req-conn rules) */
-       long long denied_sess;                  /* denied session requests (tcp-req-sess rules) */
-};
+/* counters used by listeners and frontends */
+struct be_counters {
+       unsigned int conn_max;                  /* max # of active sessions */
+       long long    cum_conn;                  /* cumulated number of received connections */
+       long long    cum_sess;                  /* cumulated number of accepted connections */
+       long long  cum_lbconn;                  /* cumulated number of sessions processed by load balancing (BE only) */
+       unsigned long last_sess;                /* last session time */
 
-struct srvcounters {
+       unsigned int cps_max;                   /* maximum of new connections received per second */
+       unsigned int sps_max;                   /* maximum of new connections accepted per second (sessions) */
+       unsigned int nbpend_max;                /* max number of pending connections with no server assigned yet (BE only) */
        unsigned int cur_sess_max;              /* max number of currently active sessions */
-       unsigned int nbpend_max;                /* max number of pending connections reached */
-       unsigned int sps_max;                   /* maximum of new sessions per second seen on this server */
 
-       long long cum_sess;                     /* cumulated number of sessions really sent to this server */
-       long long cum_lbconn;                   /* cumulated number of sessions directed by load balancing */
-       unsigned long last_sess;                 /* last session time */
+       long long bytes_in;                     /* number of bytes transferred from the client to the server */
+       long long bytes_out;                    /* number of bytes transferred from the server to the client */
 
-       long long bytes_in;                     /* number of bytes transferred from the client to the server */
-       long long bytes_out;                    /* number of bytes transferred from the server to the client */
+       long long comp_in;                      /* input bytes fed to the compressor */
+       long long comp_out;                     /* output bytes emitted by the compressor */
+       long long comp_byp;                     /* input bytes that bypassed the compressor (cpu/ram/bw limitation) */
 
-       long long failed_conns, failed_resp;    /* failed connect() and responses */
-       long long cli_aborts, srv_aborts;       /* aborted responses during DATA phase due to client or server */
-       long long retries, redispatches;        /* retried and redispatched connections */
+       long long denied_req;                   /* blocked requests because of security concerns */
+       long long denied_resp;                  /* blocked responses because of security concerns */
+
+       long long failed_conns;                 /* failed connect() attempts (BE only) */
+       long long failed_resp;                  /* failed responses (BE only) */
+       long long cli_aborts;                   /* aborted responses during DATA phase caused by the client */
+       long long srv_aborts;                   /* aborted responses during DATA phase caused by the server */
+       long long retries;                      /* retried and redispatched connections (BE only) */
+       long long redispatches;                 /* retried and redispatched connections (BE only) */
        long long failed_secu;                  /* blocked responses because of security concerns */
 
+       long long failed_checks, failed_hana;   /* failed health checks and health analyses for servers */
+       long long down_trans;                   /* up->down transitions */
+
        unsigned int q_time, c_time, d_time, t_time; /* sums of conn_time, queue_time, data_time, total_time */
 
        union {
                struct {
-                       long long rsp[6];       /* http response codes */
+                       long long cum_req;      /* cumulated number of processed HTTP requests */
+                       long long comp_rsp;     /* number of compressed responses */
+                       unsigned int rps_max;   /* maximum of new HTTP requests second observed */
+                       long long rsp[6];       /* http response codes */
                } http;
-       } p;
-
-       long long failed_checks, failed_hana;   /* failed health checks and health analyses */
-       long long down_trans;                   /* up->down transitions */
+       } p;                                    /* protocol-specific stats */
 };
 
 #endif /* _TYPES_COUNTERS_H */
index 1f14cc0bdfb7730e7505fe2f9f2d87a8c0b1aab2..d06e4e7c850eb0653bdc2ee2e638f2f7b6389d7f 100644 (file)
@@ -39,7 +39,7 @@ struct task;
 struct protocol;
 struct xprt_ops;
 struct proxy;
-struct licounters;
+struct fe_counters;
 
 /* listener state */
 enum li_state {
@@ -171,7 +171,7 @@ struct listener {
        char *name;                     /* listener's name */
        int luid;                       /* listener universally unique ID, used for SNMP */
        int options;                    /* socket options : LI_O_* */
-       struct licounters *counters;    /* statistics counters */
+       struct fe_counters *counters;   /* statistics counters */
        struct protocol *proto;         /* protocol this listener belongs to */
        struct xprt_ops *xprt;          /* transport-layer operations for this socket */
        int nbconn;                     /* current number of connections on this listener */
index 0b194cb731b9e79607a119dd808919ef2de51989..3bf5a4d46ce85c8460d1a2705a03b5bd4a13fd2d 100644 (file)
@@ -362,8 +362,8 @@ struct proxy {
        struct pool_head *req_cap_pool,         /* pools of pre-allocated char ** used to build the streams */
                         *rsp_cap_pool;
        struct list req_add, rsp_add;           /* headers to be added */
-       struct pxcounters be_counters;          /* backend statistics counters */
-       struct pxcounters fe_counters;          /* frontend statistics counters */
+       struct be_counters be_counters;         /* backend statistics counters */
+       struct fe_counters fe_counters;         /* frontend statistics counters */
 
        struct list listener_queue;             /* list of the temporarily limited listeners because of lack of a proxy resource */
        struct stktable table;                  /* table for storing sticking streams */
index c6c581c7461e77e4adda4d917e076c12ae310d61..20c314b99c4aab4be7aab9d4dba1664cdee76503 100644 (file)
@@ -192,7 +192,7 @@ struct server {
        int nbpend;                             /* number of pending connections */
        int maxqueue;                           /* maximum number of pending connections allowed */
        struct freq_ctr sess_per_sec;           /* sessions per second on this server */
-       struct srvcounters counters;            /* statistics counters */
+       struct be_counters counters;            /* statistics counters */
 
        struct list pendconns;                  /* pending connections */
        struct list actconns;                   /* active connections */
index fbd7364662124bad36194b6bc863b49271568ca5..4fc63bde32ff1bec206c996e7d392104868b90d3 100644 (file)
@@ -9009,7 +9009,7 @@ out_uri_auth_compat:
 
                        /* enable separate counters */
                        if (curproxy->options2 & PR_O2_SOCKSTAT) {
-                               listener->counters = calloc(1, sizeof(struct licounters));
+                               listener->counters = calloc(1, sizeof(*listener->counters));
                                if (!listener->name)
                                        memprintf(&listener->name, "sock-%d", listener->luid);
                        }
index bfd16994d6d29396a0fcac4dfd3d4f3c047d5c99..497aa4779077e70ec88ad95bf773da364e62f119 100644 (file)
@@ -929,7 +929,6 @@ static int stats_dump_fields_html(struct chunk *out, const struct field *stats,
                                      "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
                                      "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
                                      "<tr><th>- other responses:</th><td>%s</td></tr>"
-                                     "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
                                      "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
                                      "",
                                      U2H(stats[ST_F_REQ_TOT].u.u64),
@@ -941,8 +940,7 @@ static int stats_dump_fields_html(struct chunk *out, const struct field *stats,
                                      U2H(stats[ST_F_HRSP_3XX].u.u64),
                                      U2H(stats[ST_F_HRSP_4XX].u.u64),
                                      U2H(stats[ST_F_HRSP_5XX].u.u64),
-                                     U2H(stats[ST_F_HRSP_OTHER].u.u64),
-                                     U2H(stats[ST_F_INTERCEPTED].u.u64));
+                                     U2H(stats[ST_F_HRSP_OTHER].u.u64));
                }
 
                chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>",   U2H(stats[ST_F_QTIME].u.u32));
@@ -1547,7 +1545,6 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le
                stats[ST_F_HRSP_4XX]    = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
                stats[ST_F_HRSP_5XX]    = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
                stats[ST_F_HRSP_OTHER]  = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
-               stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->be_counters.intercepted_req);
        }
 
        stats[ST_F_CLI_ABRT]     = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
@@ -3065,7 +3062,6 @@ static int cli_parse_clear_counters(char **args, struct appctx *appctx, void *pr
                        px->fe_counters.p.http.rps_max = 0;
                        px->fe_counters.sps_max = 0;
                        px->fe_counters.cps_max = 0;
-                       px->fe_counters.nbpend_max = 0;
                }
 
                for (sv = px->srv; sv; sv = sv->next)