]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: Enhancement to stats page to provide information of last session time.
authorBhaskar Maddala <bhaskar@tumblr.com>
Mon, 3 Feb 2014 21:26:46 +0000 (16:26 -0500)
committerWilly Tarreau <w@1wt.eu>
Sat, 8 Feb 2014 00:19:58 +0000 (01:19 +0100)
Summary:
Track and report last session time on the stats page for each server
in every backend, as well as the backend.

This attempts to address the requirement in the ROADMAP

  - add a last activity date for each server (req/resp) that will be
    displayed in the stats. It will be useful with soft stop.

The stats page reports this as time elapsed since last session. This
change does not adequately address the requirement for long running
session (websocket, RDP... etc).

include/proto/backend.h
include/proto/server.h
include/types/counters.h
src/backend.c
src/dumpstats.c
src/proto_http.c
src/server.c
src/session.c

index 74caaaac1f6cdc85cf736848ca048157cc4931a7..68ba3d6175df6d795f07a1fbc01b267d9963d21a 100644 (file)
@@ -23,6 +23,7 @@
 #define _PROTO_BACKEND_H
 
 #include <common/config.h>
+#include <common/time.h>
 
 #include <types/backend.h>
 #include <types/proxy.h>
@@ -43,6 +44,13 @@ void recount_servers(struct proxy *px);
 void update_backend_weight(struct proxy *px);
 struct server *get_server_sh(struct proxy *px, const char *addr, int len);
 struct server *get_server_uh(struct proxy *px, char *uri, int uri_len);
+int be_lastsession(const struct proxy *be);
+
+/* set the time of last session on the backend */
+static void inline be_set_sess_last(struct proxy *be)
+{
+       be->be_counters.last_sess = now.tv_sec;
+}
 
 /* This function returns non-zero if a server with the given weight and state
  * is usable for LB, otherwise zero.
index 93f4f81a66cb5788b298903f11fbd7c1e93a862d..750d8d5a8261acaf9a807e7bb1ad9c033046d517 100644 (file)
 #include <unistd.h>
 
 #include <common/config.h>
+#include <common/time.h>
 #include <types/proxy.h>
 #include <types/queue.h>
 #include <types/server.h>
 
 #include <proto/queue.h>
+#include <proto/log.h>
 #include <proto/freq_ctr.h>
 
 int srv_downtime(const struct server *s);
+int srv_lastsession(const struct server *s);
 int srv_getinter(const struct check *check);
 
 /* increase the number of cumulated connections on the designated server */
@@ -44,6 +47,12 @@ static void inline srv_inc_sess_ctr(struct server *s)
                s->counters.sps_max = s->sess_per_sec.curr_ctr;
 }
 
+/* set the time of last session on the designated server */
+static void inline srv_set_sess_last(struct server *s)
+{
+       s->counters.last_sess = now.tv_sec;
+}
+
 #endif /* _PROTO_SERVER_H */
 
 /*
index efb48f66bb5934929e368cb2440e7b623b3a7cf8..ecdc7cb9587f1df8d35785f3044670e904131957 100644 (file)
@@ -29,6 +29,7 @@ struct pxcounters {
        long long    cum_conn;                  /* cumulated number of received connections */
        long long    cum_sess;                  /* cumulated number of accepted connections */
        long long  cum_lbconn;                  /* cumulated number of sessions processed by load balancing (BE only) */
+       unsigned long last_sess;                /* last session time */
 
        unsigned int cps_max;                   /* maximum of new connections received per second */
        unsigned int sps_max;                   /* maximum of new connections accepted per second (sessions) */
@@ -85,6 +86,7 @@ struct srvcounters {
 
        long long cum_sess;                     /* cumulated number of sessions really sent to this server */
        long long cum_lbconn;                   /* cumulated number of sessions directed by load balancing */
+       unsigned long last_sess;                 /* last session time */
 
        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 */
index 8fcce7dd2ecae48d858903e4022f60ee297f27e8..e561919b016f3e5d1b1cb6ff5d4abf65d7c02559 100644 (file)
 #include <proto/stream_interface.h>
 #include <proto/task.h>
 
+int be_lastsession(const struct proxy *be)
+{
+       if (be->be_counters.last_sess)
+               return now.tv_sec - be->be_counters.last_sess;
+
+       return -1;
+}
+
 /* helper function to invoke the correct hash method */
 static unsigned long gen_hash(const struct proxy* px, const char* key, unsigned long len)
 {
@@ -668,6 +676,7 @@ int assign_server(struct session *s)
                        goto out;
                }
                else if (srv != prev_srv) {
+                       be_set_sess_last(s->be);
                        s->be->be_counters.cum_lbconn++;
                        srv->counters.cum_lbconn++;
                }
@@ -1164,6 +1173,8 @@ int srv_redispatch_connect(struct session *t)
 
                if (srv)
                        srv_inc_sess_ctr(srv);
+               if (srv)
+                       srv_set_sess_last(srv);
                if (srv)
                        srv->counters.failed_conns++;
                t->be->be_counters.failed_conns++;
index 25997854f0375c87619ed3c9f0da61631da2f830..d147d0fbb782ec2cb9450d7080fe8af8099eb9b6 100644 (file)
@@ -433,7 +433,7 @@ static void stats_dump_csv_header()
        chunk_appendf(&trash,
                      "# pxname,svname,"
                      "qcur,qmax,"
-                     "scur,smax,slim,stot,"
+                     "scur,smax,slim,stot,lastsess,"
                      "bin,bout,"
                      "dreq,dresp,"
                      "ereq,econ,eresp,"
@@ -2467,8 +2467,8 @@ static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
 
                chunk_appendf(&trash,
                              "</table></div></u></td>"
-                             /* sessions: lbtot */
-                             "<td></td>"
+                             /* sessions: lbtot, lastsess */
+                             "<td></td><td></td>"
                              /* bytes : in */
                              "<td>%s</td>"
                              "",
@@ -2505,8 +2505,8 @@ static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
                chunk_appendf(&trash,
                              /* pxid, name, queue cur, queue max, */
                              "%s,FRONTEND,,,"
-                             /* sessions : current, max, limit, total */
-                             "%d,%d,%d,%lld,"
+                             /* sessions : current, max, limit, total, lastsess */
+                             "%d,%d,%d,%lld,,"
                              /* bytes : in, out */
                              "%lld,%lld,"
                              /* denied: req, resp */
@@ -2625,9 +2625,9 @@ static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, st
                              "%s</td><td colspan=3></td>"
                              /* sessions rate: current, max, limit */
                              "<td colspan=3>&nbsp;</td>"
-                             /* sessions: current, max, limit, total, lbtot */
+                             /* sessions: current, max, limit, total, lbtot, lastsess */
                              "<td>%s</td><td>%s</td><td>%s</td>"
-                             "<td>%s</td><td>&nbsp;</td>"
+                             "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
                              /* bytes: in, out */
                              "<td>%s</td><td>%s</td>"
                              "",
@@ -2655,8 +2655,8 @@ static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, st
                chunk_appendf(&trash,
                              /* pxid, name, queue cur, queue max, */
                              "%s,%s,,,"
-                             /* sessions: current, max, limit, total */
-                             "%d,%d,%d,%lld,"
+                             /* sessions: current, max, limit, total, lastsess */
+                             "%d,%d,%d,%lld,,"
                              /* bytes: in, out */
                              "%lld,%lld,"
                              /* denied: req, resp */
@@ -2829,9 +2829,10 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
 
                chunk_appendf(&trash,
                              "</table></div></u></td>"
-                             /* sessions: lbtot */
-                             "<td>%s</td>",
-                             U2H(sv->counters.cum_lbconn));
+                             /* sessions: lbtot, last */
+                             "<td>%s</td><td>%s</td>",
+                             U2H(sv->counters.cum_lbconn),
+                             human_time(srv_lastsession(sv), 1));
 
                chunk_appendf(&trash,
                              /* bytes : in, out */
@@ -2957,8 +2958,8 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
                              "%s,%s,"
                              /* queue : current, max */
                              "%d,%d,"
-                             /* sessions : current, max, limit, total */
-                             "%d,%d,%s,%lld,"
+                             /* sessions : current, max, limit, total, lastsess */
+                             "%d,%d,%s,%lld,%d,"
                              /* bytes : in, out */
                              "%lld,%lld,"
                              /* denied: req, resp */
@@ -2971,6 +2972,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
                              px->id, sv->id,
                              sv->nbpend, sv->counters.nbpend_max,
                              sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess,
+                             srv_lastsession(sv),
                              sv->counters.bytes_in, sv->counters.bytes_out,
                              sv->counters.failed_secu,
                              sv->counters.failed_conns, sv->counters.failed_resp,
@@ -3177,12 +3179,13 @@ static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, in
 
                chunk_appendf(&trash,
                              "</table></div></u></td>"
-                             /* sessions: lbtot */
-                             "<td>%s</td>"
+                             /* sessions: lbtot, last */
+                             "<td>%s</td><td>%s</td>"
                              /* bytes: in */
                              "<td>%s</td>"
                              "",
                              U2H(px->be_counters.cum_lbconn),
+                             human_time(be_lastsession(px), 1),
                              U2H(px->be_counters.bytes_in));
 
                chunk_appendf(&trash,
@@ -3238,8 +3241,8 @@ static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, in
                              "%s,BACKEND,"
                              /* queue : current, max */
                              "%d,%d,"
-                             /* sessions : current, max, limit, total */
-                             "%d,%d,%d,%lld,"
+                             /* sessions : current, max, limit, total, lastsess */
+                             "%d,%d,%d,%lld,%s,"
                              /* bytes : in, out */
                              "%lld,%lld,"
                              /* denied: req, resp */
@@ -3265,6 +3268,7 @@ static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, in
                              px->id,
                              px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
                              px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
+                             human_time(be_lastsession(px), 1),
                              px->be_counters.bytes_in, px->be_counters.bytes_out,
                              px->be_counters.denied_req, px->be_counters.denied_resp,
                              px->be_counters.failed_conns, px->be_counters.failed_resp,
@@ -3378,7 +3382,7 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
        chunk_appendf(&trash,
                      "<th rowspan=2></th>"
                      "<th colspan=3>Queue</th>"
-                     "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
+                     "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
                      "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
                      "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
                      "<th colspan=9>Server</th>"
@@ -3386,7 +3390,7 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
                      "<tr class=\"titre\">"
                      "<th>Cur</th><th>Max</th><th>Limit</th>"
                      "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
-                     "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
+                     "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>"
                      "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
                      "<th>Resp</th><th>Retr</th><th>Redis</th>"
                      "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
index 6c4ba7a7b85e757bc093da69b41e8bb9ac7e8b01..371b5233083b730befce2b3a0709ac56d8c373d6 100644 (file)
@@ -943,6 +943,7 @@ void http_perform_server_redirect(struct session *s, struct stream_interface *si
 
        /* FIXME: we should increase a counter of redirects per server and per backend. */
        srv_inc_sess_ctr(srv);
+       srv_set_sess_last(srv);
 }
 
 /* Return the error message corresponding to si->err_type. It is assumed
index d91c726a4590a7e9e51c7baf813297e90db563b3..ccae58be261cf7e4131987469ed3fbf38dc9001a 100644 (file)
@@ -30,6 +30,14 @@ int srv_downtime(const struct server *s)
        return now.tv_sec - s->last_change + s->down_time;
 }
 
+int srv_lastsession(const struct server *s)
+{
+       if (s->counters.last_sess)
+               return now.tv_sec - s->counters.last_sess;
+
+       return -1;
+}
+
 int srv_getinter(const struct check *check)
 {
        const struct server *s = check->server;
index 0a0367785691af4d4b246ee9ee0e5642660472b6..b3da759b47a6916c1029d39dadd6e17013c89fdd 100644 (file)
@@ -974,6 +974,8 @@ static void sess_update_stream_int(struct session *s, struct stream_interface *s
                        /* state = SI_ST_CON or SI_ST_EST now */
                        if (srv)
                                srv_inc_sess_ctr(srv);
+                       if (srv)
+                               srv_set_sess_last(srv);
                        return;
                }
 
@@ -987,6 +989,8 @@ static void sess_update_stream_int(struct session *s, struct stream_interface *s
 
                        if (srv)
                                srv_inc_sess_ctr(srv);
+                       if (srv)
+                               srv_set_sess_last(srv);
                        if (srv)
                                srv->counters.failed_conns++;
                        s->be->be_counters.failed_conns++;