]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: report HTTP compression stats per frontend and per backend
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Nov 2012 07:27:21 +0000 (08:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Nov 2012 00:07:40 +0000 (01:07 +0100)
It was a bit frustrating to have no idea about the bandwidth saved by
HTTP compression. Now we have per-frontend and per-backend stats. The
stats on the HTTP interface are shown in a hover title in the "bytes out"
column if at least something was fed to the compressor. 3 new columns
appeared in the CSV stats output.

doc/configuration.txt
include/types/counters.h
src/compression.c
src/dumpstats.c

index 663ffde132616ad7b2106f23f28865c8fb3216c5..23b679813b65457f10cf035a73286f806dea7fc3 100644 (file)
@@ -11026,6 +11026,9 @@ page. Both means provide a CSV format whose fields follow.
  48. req_tot: total number of HTTP requests received
  49. cli_abrt: number of data transfers aborted by the client
  50. srv_abrt: number of data transfers aborted by the server (inc. in eresp)
+ 51. comp_in: number of HTTP response bytes fed to the compressor
+ 52. comp_out: number of HTTP response bytes emitted by the compressor
+ 53. comp_byp: number of bytes that bypassed the HTTP compressor (CPU/BW limit)
 
 
 9.2. Unix Socket commands
index 391915acd9b7e77fc4f36f469a23f64a14fdf59a..8326429a65f57afc18eae712325c4430f6cf3ccc 100644 (file)
@@ -37,6 +37,10 @@ struct pxcounters {
        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 denied_req;                   /* blocked requests/responses because of security concerns */
        long long denied_resp;                  /* blocked requests/responses because of security concerns */
        long long failed_req;                   /* failed requests (eg: invalid or timeout) */
index 0459aa3015ad7fb8536f11dac5d847c5a343fb95..3622d4091cb1afce9cf1543e2c9407f4df074e29 100644 (file)
@@ -217,7 +217,7 @@ int http_compression_buffer_add_data(struct session *s, struct buffer *in, struc
  */
 int http_compression_buffer_end(struct session *s, struct buffer **in, struct buffer **out, int end)
 {
-       int to_forward;
+       int to_forward, forwarded;
        int left;
        struct http_msg *msg = &s->txn.rsp;
        struct buffer *ib = *in, *ob = *out;
@@ -262,9 +262,17 @@ int http_compression_buffer_end(struct session *s, struct buffer **in, struct bu
        }
 
        to_forward = ob->i;
+
        /* update input rate */
-       if (s->comp_ctx && s->comp_ctx->cur_lvl > 0)
-               update_freq_ctr(&global.comp_bps_in, ib->o - ob->o);
+       forwarded = ib->o - ob->o;
+       if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) {
+               update_freq_ctr(&global.comp_bps_in, forwarded);
+               s->fe->fe_counters.comp_in += forwarded;
+               s->be->be_counters.comp_in += forwarded;
+       } else {
+               s->fe->fe_counters.comp_byp += forwarded;
+               s->be->be_counters.comp_byp += forwarded;
+       }
 
        /* copy the remaining data in the tmp buffer. */
        if (ib->i > 0) {
@@ -281,8 +289,11 @@ int http_compression_buffer_end(struct session *s, struct buffer **in, struct bu
        *in = ob;
        *out = ib;
 
-       if (s->comp_ctx && s->comp_ctx->cur_lvl > 0)
+       if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) {
                update_freq_ctr(&global.comp_bps_out, to_forward);
+               s->fe->fe_counters.comp_out += to_forward;
+               s->be->be_counters.comp_out += to_forward;
+       }
 
        /* forward the new chunk without remaining data */
        b_adv(ob, to_forward);
index 997bdec595c9ffc0444edb69c8837db6a6faef53..a9ecdb3c812185efae60f627dcaba44181cd8a1e 100644 (file)
@@ -379,6 +379,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,"
                            "\n");
 }
 
@@ -2477,13 +2478,25 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_appendf(&trash,
                                     /* sessions: total, lbtot */
                                     ">%s%s%s</td><td></td>"
-                                    /* bytes : in, out */
-                                    "<td>%s</td><td>%s</td>"
+                                    /* bytes : in */
+                                    "<td>%s</td><td"
                                     "",
                                     (px->mode == PR_MODE_HTTP)?"<u>":"",
                                     U2H6(px->fe_counters.cum_sess),
                                     (px->mode == PR_MODE_HTTP)?"</u>":"",
-                                    U2H7(px->fe_counters.bytes_in), U2H8(px->fe_counters.bytes_out));
+                                    U2H7(px->fe_counters.bytes_in));
+
+                               /* compression stats (via td title): comp_in, comp_out, comp_byp */
+                               chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld\"",
+                                    px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
+
+                               chunk_appendf(&trash,
+                                    /* bytes: out */
+                                    ">%s%s%s</td>"
+                                    "",
+                                    (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
+                                    U2H0(px->fe_counters.bytes_out),
+                                    (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
 
                                chunk_appendf(&trash,
                                     /* denied: req, resp */
@@ -2559,6 +2572,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                /* errors: cli_aborts, srv_aborts */
                                chunk_appendf(&trash, ",,");
 
+                               /* compression: in, out, bypassed */
+                               chunk_appendf(&trash, "%lld,%lld,%lld,",
+                                     px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
+
                                /* finish with EOL */
                                chunk_appendf(&trash, "\n");
                        }
@@ -3186,14 +3203,26 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_appendf(&trash,
                                     /* sessions: total, lbtot */
                                     ">%s%s%s</td><td>%s</td>"
-                                    /* bytes: in, out */
-                                    "<td>%s</td><td>%s</td>"
+                                    /* bytes: in */
+                                    "<td>%s</td><td"
                                     "",
                                     (px->mode == PR_MODE_HTTP)?"<u>":"",
                                     U2H6(px->be_counters.cum_conn),
                                     (px->mode == PR_MODE_HTTP)?"</u>":"",
                                     U2H7(px->be_counters.cum_lbconn),
-                                    U2H8(px->be_counters.bytes_in), U2H9(px->be_counters.bytes_out));
+                                    U2H8(px->be_counters.bytes_in));
+
+                               /* compression stats (via td title): comp_in, comp_out, comp_byp */
+                               chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld\"",
+                                    px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
+
+                               chunk_appendf(&trash,
+                                    /* bytes: out */
+                                    ">%s%s%s</td>"
+                                    "",
+                                    (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
+                                    U2H0(px->be_counters.bytes_out),
+                                    (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
 
                                chunk_appendf(&trash,
                                     /* denied: req, resp */
@@ -3300,6 +3329,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
                                chunk_appendf(&trash, "%lld,%lld,",
                                             px->be_counters.cli_aborts, px->be_counters.srv_aborts);
 
+                               /* compression: in, out, bypassed */
+                               chunk_appendf(&trash, "%lld,%lld,%lld,",
+                                     px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
+
                                /* finish with EOL */
                                chunk_appendf(&trash, "\n");