From: Willy Tarreau Date: Wed, 21 Nov 2012 07:27:21 +0000 (+0100) Subject: MINOR: stats: report HTTP compression stats per frontend and per backend X-Git-Tag: v1.5-dev13~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55058a7c1e82f2e0a59c4e39090ce72736382c81;p=thirdparty%2Fhaproxy.git MINOR: stats: report HTTP compression stats per frontend and per backend 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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 663ffde132..23b679813b 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 diff --git a/include/types/counters.h b/include/types/counters.h index 391915acd9..8326429a65 100644 --- a/include/types/counters.h +++ b/include/types/counters.h @@ -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) */ diff --git a/src/compression.c b/src/compression.c index 0459aa3015..3622d4091c 100644 --- a/src/compression.c +++ b/src/compression.c @@ -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); diff --git a/src/dumpstats.c b/src/dumpstats.c index 997bdec595..a9ecdb3c81 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -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" - /* bytes : in, out */ - "%s%s" + /* bytes : in */ + "%smode == PR_MODE_HTTP)?"":"", U2H6(px->fe_counters.cum_sess), (px->mode == PR_MODE_HTTP)?"":"", - 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" + "", + (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "":"", + U2H0(px->fe_counters.bytes_out), + (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "":""); 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%s" - /* bytes: in, out */ - "%s%s" + /* bytes: in */ + "%smode == PR_MODE_HTTP)?"":"", U2H6(px->be_counters.cum_conn), (px->mode == PR_MODE_HTTP)?"":"", 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" + "", + (px->be_counters.comp_in || px->be_counters.comp_byp) ? "":"", + U2H0(px->be_counters.bytes_out), + (px->be_counters.comp_in || px->be_counters.comp_byp) ? "":""); 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");