>From d529a265e60ea3366452329e2f462a0bd02d8e58 Mon Sep 17 00:00:00 2001
From: Krzysztof Piotr Oledzki <o...@ans.pl>
Date: Sat, 24 Oct 2009 15:36:15 +0200
Subject: [MINOR] Collect & provide http response codes for frontends, fix 
backends

This patch extends and corrects the functionality introduced by
"Collect & provide http response codes received from servers":
 - responses are now also accounted for frontends
 - backend's and frontend's counters are incremented based
   on responses sent to client, not received from servers
---
 src/dumpstats.c  |   47 ++++++++++++++++++++++++++++++++++++++---------
 src/proto_http.c |    1 -
 src/session.c    |   15 +++++++++++++++
 3 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/src/dumpstats.c b/src/dumpstats.c
index 1f0ae90..866f499 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -1278,16 +1278,33 @@ int stats_dump_proxy(struct session *s, struct proxy 
*px, struct uri_auth *uri)
                                     "<a class=lfsb 
href=\"#%s/Frontend\">Frontend</a></td><td colspan=3></td>"
                                     /* sessions rate : current, max, limit */
                                     "<td>%s</td><td>%s</td><td>%s</td>"
-                                    /* sessions : current, max, limit, total, 
lbtot */
+                                    /* sessions: current, max, limit */
                                     "<td>%s</td><td>%s</td><td>%s</td>"
-                                    "<td>%s</td><td></td>"
-                                    /* bytes : in, out */
-                                    "<td>%s</td><td>%s</td>"
+                                    "<td"
                                     "",
                                     px->id, px->id,
                                     U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
                                     U2H1(px->counters.fe_sps_max), 
LIM2A2(px->fe_sps_lim, "-"),
-                                    U2H3(px->feconn), 
U2H4(px->counters.feconn_max), U2H5(px->maxconn),
+                                    U2H3(px->feconn), 
U2H4(px->counters.feconn_max), U2H5(px->maxconn));
+
+                               /* http response (via td title): 1xx, 2xx, 3xx, 
4xx, 5xx, other */
+                               if (px->mode == PR_MODE_HTTP) {
+                                       int i;
+
+                                       chunk_printf(&msg, " title=\"rsp 
codes:");
+
+                                       for (i = 1; i < 6; i++)
+                                               chunk_printf(&msg, " 
%dxx=%lld,", i, px->counters.p.http.rsp[i]);
+
+                                       chunk_printf(&msg, " other=%lld\"", 
px->counters.p.http.rsp[0]);
+                               }
+
+                               chunk_printf(&msg,
+                                    /* sessions: total, lbtot */
+                                    ">%s</td><td></td>"
+                                    /* bytes : in, out */
+                                    "<td>%s</td><td>%s</td>"
+                                    "",
                                     U2H6(px->counters.cum_feconn), 
U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out));
 
                                chunk_printf(&msg,
@@ -1329,10 +1346,7 @@ int stats_dump_proxy(struct session *s, struct proxy 
*px, struct uri_auth *uri)
                                     /* rate, rate_lim, rate_max */
                                     "%u,%u,%u,"
                                     /* check_status, check_code, 
check_duration */
-                                    ",,,"
-                                    /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, 
other */
-                                    ",,,,,,"
-                                    "\n",
+                                    ",,,",
                                     px->id,
                                     px->feconn, px->counters.feconn_max, 
px->maxconn, px->counters.cum_feconn,
                                     px->counters.bytes_in, 
px->counters.bytes_out,
@@ -1343,6 +1357,21 @@ int stats_dump_proxy(struct session *s, struct proxy 
*px, struct uri_auth *uri)
                                     relative_pid, px->uuid, STATS_TYPE_FE,
                                     read_freq_ctr(&px->fe_sess_per_sec),
                                     px->fe_sps_lim, px->counters.fe_sps_max);
+
+                               /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, 
other */
+                               if (px->mode == PR_MODE_HTTP) {
+                                       int i;
+
+                                       for (i=1; i<6; i++)
+                                               chunk_printf(&msg, "%lld,", 
px->counters.p.http.rsp[i]);
+
+                                       chunk_printf(&msg, "%lld,", 
px->counters.p.http.rsp[0]);
+                               } else {
+                                       chunk_printf(&msg, ",,,,,,");
+                               }
+
+                               /* finish with EOL */
+                               chunk_printf(&msg, "\n");
                        }
 
                        if (buffer_feed_chunk(rep, &msg) >= 0)
diff --git a/src/proto_http.c b/src/proto_http.c
index b83beb9..b78fc53 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -3052,7 +3052,6 @@ int http_wait_for_response(struct session *s, struct 
buffer *rep, int an_bit)
        if (n < 1 || n > 5)
                n = 0;
        s->srv->counters.p.http.rsp[n]++;
-       s->be->counters.p.http.rsp[n]++;
 
        txn->status = strl2ui(rep->data + msg->sl.st.c, msg->sl.st.c_l);
 
diff --git a/src/session.c b/src/session.c
index b010f59..03285e2 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1302,6 +1302,21 @@ resync_stream_interface:
        s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
        session_process_counters(s);
 
+       if (s->txn.status) {
+               int n;
+
+               n = s->txn.status / 100;
+               if (n < 1 || n > 5)
+                       n = 0;
+
+               if (s->fe->mode == PR_MODE_HTTP)
+                       s->fe->counters.p.http.rsp[n]++;
+
+               if ((s->flags & SN_BE_ASSIGNED) && (s->fe != s->be) &&
+                   (s->be->mode == PR_MODE_HTTP))
+                       s->be->counters.p.http.rsp[n]++;
+       }
+
        /* let's do a final log if we need it */
        if (s->logs.logwait &&
            !(s->flags & SN_MONITOR) &&
-- 
1.6.4.2


Reply via email to