From ddbb82ff4737847e67d7afb642a3f5788f08d69c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 5 Dec 2007 10:34:49 +0100 Subject: [PATCH] [STATS] report the number of times each server was selected One user reported that an indicator was missing in the statistics: the number of times each server was selected by load balancing. It is in fact the total number of sessions assigned to a server by the load balancing algorithm. It should directly reflect the weight for "fair" algorithms such as round-robin, since it will not account for persistant connections. It should help a lot tuning each server's weight depending on the load it receives. --- include/types/proxy.h | 1 + include/types/server.h | 1 + src/backend.c | 2 ++ src/dumpstats.c | 46 +++++++++++++++++++++++++----------------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/include/types/proxy.h b/include/types/proxy.h index 9d1fae6cf..240b99b69 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -184,6 +184,7 @@ struct proxy { unsigned int feconn, feconn_max; /* # of active frontend sessions */ unsigned int beconn, beconn_max; /* # of active backend sessions */ unsigned int cum_feconn, cum_beconn; /* cumulated number of processed sessions */ + unsigned int cum_lbconn; /* cumulated number of sessions processed by load balancing */ unsigned int maxconn; /* max # of active sessions on the frontend */ unsigned int fullconn; /* #conns on backend above which servers are used at full load */ struct in_addr except_net, except_mask; /* don't x-forward-for for this address. FIXME: should support IPv6 */ diff --git a/include/types/server.h b/include/types/server.h index 614775bec..5c47d17ed 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -116,6 +116,7 @@ struct server { unsigned retries; /* retried connections */ unsigned failed_secu; /* blocked responses because of security concerns */ unsigned cum_sess; /* cumulated number of sessions really sent to this server */ + unsigned cum_lbconn; /* cumulated number of sessions directed by load balancing */ 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 */ diff --git a/src/backend.c b/src/backend.c index 6aa7eaff4..d456afd16 100644 --- a/src/backend.c +++ b/src/backend.c @@ -955,6 +955,8 @@ int assign_server(struct session *s) /* unknown balancing algorithm */ return SRV_STATUS_INTERNAL; } + s->be->cum_lbconn++; + s->srv->cum_lbconn++; } else if (s->be->options & PR_O_HTTP_PROXY) { if (!s->srv_addr.sin_addr.s_addr) diff --git a/src/dumpstats.c b/src/dumpstats.c index 6d4ea5440..f7522719c 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -171,7 +171,7 @@ int print_csv_header(struct chunk *msg, int size) "wretr,wredis," "status,weight,act,bck," "chkfail,chkdown,lastchg,downtime,qlimit," - "pid,iid,sid,throttle," + "pid,iid,sid,throttle,lbtot," "\n"); } @@ -589,21 +589,21 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, if (flags & STAT_FMT_HTML) { /* print a new table */ chunk_printf(&msg, sizeof(trash), - "\n" + "
\n" "" "" - "" + "" "\n" "" "" - "" + "" "" "" "" "\n" "" "" - "" + "" "" "" "" @@ -626,9 +626,10 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, chunk_printf(&msg, sizeof(trash), /* name, queue */ "" - /* sessions : current, max, limit, cumul */ + /* sessions : current, max, limit, total, lbtot */ "" "" + "" /* bytes : in, out */ "" /* denied: req, resp */ @@ -652,7 +653,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, chunk_printf(&msg, sizeof(trash), /* pxid, name, queue cur, queue max, */ "%s,FRONTEND,,," - /* sessions : current, max, limit, cumul */ + /* sessions : current, max, limit, total */ "%d,%d,%d,%d," /* bytes : in, out */ "%lld,%lld," @@ -666,8 +667,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "%s," /* rest of server: nothing */ ",,,,,,,," - /* pid, iid, sid, throttle, */ - "%d,%d,0,," + /* pid, iid, sid, throttle, lbtot, */ + "%d,%d,0,,," "\n", px->id, px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, @@ -728,9 +729,10 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "" /* queue : current, max, limit */ "" - /* sessions : current, max, limit, cumul */ + /* sessions : current, max, limit, total, lbtot */ "" "" + "" /* bytes : in, out */ "" /* denied: req, resp */ @@ -743,7 +745,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state, sv->id, sv->nbpend, sv->nbpend_max, LIM2A0(sv->maxqueue, "-"), - sv->cur_sess, sv->cur_sess_max, LIM2A1(sv->maxconn, "-"), sv->cum_sess, + sv->cur_sess, sv->cur_sess_max, LIM2A1(sv->maxconn, "-"), + sv->cum_sess, sv->cum_lbconn, sv->bytes_in, sv->bytes_out, sv->failed_secu, sv->failed_conns, sv->failed_resp, @@ -805,7 +808,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "%s,%s," /* queue : current, max */ "%d,%d," - /* sessions : current, max, limit, cumul */ + /* sessions : current, max, limit, total */ "%d,%d,%s,%d," /* bytes : in, out */ "%lld,%lld," @@ -864,6 +867,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, chunk_printf(&msg, sizeof(trash), "%d", ratio); } + /* sessions: lbtot */ + chunk_printf(&msg, sizeof(trash), ",%d", sv->cum_lbconn); /* ',' then EOL */ chunk_printf(&msg, sizeof(trash), ",\n"); } @@ -885,8 +890,10 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "" /* queue : current, max */ "" - /* sessions : current, max, limit, cumul. */ - "" + /* sessions : current, max, limit, total, lbtot */ + "" + "" + "" /* bytes : in, out */ "" /* denied: req, resp */ @@ -902,7 +909,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "" "", px->nbpend /* or px->totpend ? */, px->nbpend_max, - px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, + px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, px->cum_lbconn, px->bytes_in, px->bytes_out, px->denied_req, px->denied_resp, px->failed_conns, px->failed_resp, @@ -927,7 +934,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "%s,BACKEND," /* queue : current, max */ "%d,%d," - /* sessions : current, max, limit, cumul */ + /* sessions : current, max, limit, total */ "%d,%d,%d,%d," /* bytes : in, out */ "%lld,%lld," @@ -945,8 +952,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, "%d,%d,%d," /* rest of backend: nothing, down transitions, last change, total downtime */ ",%d,%d,%d,," - /* pid, iid, sid, throttle, */ - "%d,%d,0,," + /* pid, iid, sid, throttle, lbtot, */ + "%d,%d,0,,%d," "\n", px->id, px->nbpend /* or px->totpend ? */, px->nbpend_max, @@ -960,7 +967,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, px->srv_act, px->srv_bck, px->down_trans, now.tv_sec - px->last_change, px->srv?be_downtime(px):0, - relative_pid, px->uuid); + relative_pid, px->uuid, + px->cum_lbconn); } if (buffer_write_chunk(rep, &msg) != 0) return 0;
%s
QueueSessionsQueueSessionsBytesDeniedErrorsWarningsServer
CurMaxLimitCurMaxLimitCumulInOutLimitTotalLbTotInOutReqRespReqConnRespRetrRedisStatusWghtAct
Frontend%d%d%d%d%lld%lld
%s%d%d%s%d%d%s%d%d%lld%lld
Backend%d%d%d%d%d%d%d%d%d%d%d%lld%lld%s %s%d%d%d