]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: report the total number of compressed responses per front/back
authorWilly Tarreau <w@1wt.eu>
Sat, 24 Nov 2012 13:54:13 +0000 (14:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 24 Nov 2012 13:54:13 +0000 (14:54 +0100)
Depending on the content-types and accept-encoding fields, some responses
might or might not be compressed. Let's have a counter of the number of
compressed responses and report it in the stats to help improve compression
usage.

Some cosmetic issues were fixed in the CSV output too (missing commas at the
end).

include/types/counters.h
src/dumpstats.c
src/proto_http.c
src/session.c

index 8326429a65f57afc18eae712325c4430f6cf3ccc..efb48f66bb5934929e368cb2440e7b623b3a7cf8 100644 (file)
@@ -57,6 +57,7 @@ struct pxcounters {
        union {
                struct {
                        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;
index ec27db8da82ddc731db29d9bbdf14ac2c038636e..0fef8f4dfc8ae44ad056c6e268656fd582b1682d 100644 (file)
@@ -380,7 +380,7 @@ static int print_csv_header(struct chunk *msg)
                            "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
                            "req_rate,req_rate_max,req_tot,"
                            "cli_abrt,srv_abrt,"
-                            "comp_in, comp_out, comp_byp,"
+                           "comp_in,comp_out,comp_byp,comp_rsp,"
                            "\n");
 }
 
@@ -2473,6 +2473,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                                chunk_appendf(&trash, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]);
 
                                        chunk_appendf(&trash, " other=%lld,", px->fe_counters.p.http.rsp[0]);
+                                       chunk_appendf(&trash, " compressed=%lld (%d%%)",
+                                                     px->fe_counters.p.http.comp_rsp,
+                                                     px->fe_counters.p.http.cum_req ?
+                                                     (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.cum_req) : 0);
                                        chunk_appendf(&trash, " intercepted=%lld\"", px->fe_counters.intercepted_req);
                                }
 
@@ -2579,6 +2583,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_appendf(&trash, "%lld,%lld,%lld,",
                                      px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
 
+                               /* compression: comp_rsp */
+                               chunk_appendf(&trash, "%lld,",
+                                     px->fe_counters.p.http.comp_rsp);
+
                                /* finish with EOL */
                                chunk_appendf(&trash, "\n");
                        }
@@ -2708,6 +2716,8 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                     ",,,"
                                     /* errors: cli_aborts, srv_aborts */
                                     ",,"
+                                    /* compression: in, out, bypassed, comp_rsp */
+                                    ",,,,"
                                     "\n",
                                     px->id, l->name,
                                     l->nbconn, l->counters->conn_max,
@@ -3126,6 +3136,9 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_appendf(&trash, "%lld,%lld,",
                                             sv->counters.cli_aborts, sv->counters.srv_aborts);
 
+                               /* compression: in, out, bypassed, comp_rsp */
+                               chunk_appendf(&trash, ",,,,");
+
                                /* finish with EOL */
                                chunk_appendf(&trash, "\n");
                        }
@@ -3195,12 +3208,16 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                if (px->mode == PR_MODE_HTTP) {
                                        int i;
 
-                                       chunk_appendf(&trash, " title=\"rsp codes:");
+                                       chunk_appendf(&trash, " title=\"%lld requests:", px->be_counters.p.http.cum_req);
 
                                        for (i = 1; i < 6; i++)
                                                chunk_appendf(&trash, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]);
 
-                                       chunk_appendf(&trash, " other=%lld\"", px->be_counters.p.http.rsp[0]);
+                                       chunk_appendf(&trash, " other=%lld ", px->be_counters.p.http.rsp[0]);
+                                       chunk_appendf(&trash, " compressed=%lld (%d%%)\"",
+                                                     px->be_counters.p.http.comp_rsp,
+                                                     px->be_counters.p.http.cum_req ?
+                                                     (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.cum_req) : 0);
                                }
 
                                chunk_appendf(&trash,
@@ -3338,6 +3355,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_appendf(&trash, "%lld,%lld,%lld,",
                                      px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
 
+                               /* compression: comp_rsp */
+                               chunk_appendf(&trash, "%lld,",
+                                     px->be_counters.p.http.comp_rsp);
+
                                /* finish with EOL */
                                chunk_appendf(&trash, "\n");
 
index aea1ec22f02e2c3dea63bd3b6a92445142d3c7b8..19ddbec31b2b117c6e9383ad7d8e6355c76fb3b1 100644 (file)
@@ -4027,12 +4027,18 @@ void http_end_txn_clean_session(struct session *s)
                if (n < 1 || n > 5)
                        n = 0;
 
-               if (s->fe->mode == PR_MODE_HTTP)
+               if (s->fe->mode == PR_MODE_HTTP) {
                        s->fe->fe_counters.p.http.rsp[n]++;
-
+                       if (s->comp_algo)
+                               s->fe->fe_counters.p.http.comp_rsp++;
+               }
                if ((s->flags & SN_BE_ASSIGNED) &&
-                   (s->be->mode == PR_MODE_HTTP))
+                   (s->be->mode == PR_MODE_HTTP)) {
                        s->be->be_counters.p.http.rsp[n]++;
+                       s->be->be_counters.p.http.cum_req++;
+                       if (s->comp_algo)
+                               s->be->be_counters.p.http.comp_rsp++;
+               }
        }
 
        /* don't count other requests' data */
index 0a070568b137cad2ff2c1dcf4f3e01bb79bd3a4a..9aac91d40ec0fcfb2df802032ed3ee46aaec89ab 100644 (file)
@@ -2433,12 +2433,18 @@ struct task *process_session(struct task *t)
                if (n < 1 || n > 5)
                        n = 0;
 
-               if (s->fe->mode == PR_MODE_HTTP)
+               if (s->fe->mode == PR_MODE_HTTP) {
                        s->fe->fe_counters.p.http.rsp[n]++;
-
+                       if (s->comp_algo)
+                               s->fe->fe_counters.p.http.comp_rsp++;
+               }
                if ((s->flags & SN_BE_ASSIGNED) &&
-                   (s->be->mode == PR_MODE_HTTP))
+                   (s->be->mode == PR_MODE_HTTP)) {
                        s->be->be_counters.p.http.rsp[n]++;
+                       s->be->be_counters.p.http.cum_req++;
+                       if (s->comp_algo)
+                               s->be->be_counters.p.http.comp_rsp++;
+               }
        }
 
        /* let's do a final log if we need it */