From 5e16cbc3bd0eb4a38a59d71a88ce9065338db65a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 24 Nov 2012 14:54:13 +0100 Subject: [PATCH] MINOR: stats: report the total number of compressed responses per front/back 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 | 1 + src/dumpstats.c | 27 ++++++++++++++++++++++++--- src/proto_http.c | 12 +++++++++--- src/session.c | 12 +++++++++--- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/include/types/counters.h b/include/types/counters.h index 8326429a6..efb48f66b 100644 --- a/include/types/counters.h +++ b/include/types/counters.h @@ -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; diff --git a/src/dumpstats.c b/src/dumpstats.c index ec27db8da..0fef8f4df 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -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"); diff --git a/src/proto_http.c b/src/proto_http.c index aea1ec22f..19ddbec31 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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 */ diff --git a/src/session.c b/src/session.c index 0a070568b..9aac91d40 100644 --- a/src/session.c +++ b/src/session.c @@ -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 */