[MINOR] added byte count to sessions and statistics.

Now the stats page reports the IN and OUT byte counts per FE,
BE and SRV.
This commit is contained in:
Willy Tarreau 2007-01-02 00:28:21 +01:00
parent 41dff82b54
commit 35d66b0c28
7 changed files with 37 additions and 14 deletions

View File

@ -74,6 +74,8 @@ struct proxy {
struct listener *listen; /* the listen addresses and sockets */
struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
int state; /* proxy state */
int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
struct sockaddr_in dispatch_addr; /* the default address to connect to */
struct proxy *fiprm, *beprm; /* proxy we find filter and backend params from (default: self) */
union {
@ -114,9 +116,9 @@ struct proxy {
unsigned failed_conns, failed_resp; /* failed connect() and responses */
unsigned denied_req, denied_resp; /* blocked requests/responses because of security concerns */
unsigned failed_req; /* failed requests (eg: invalid or timeout) */
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 */
int conn_retries; /* maximum number of connect retries */
int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
int cap; /* supported capabilities (PR_CAP_*) */
struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
#ifdef CONFIG_HAP_CTTPROXY

View File

@ -82,6 +82,8 @@ struct server {
unsigned failed_checks, down_trans; /* failed checks and up-down transitions */
unsigned failed_conns, failed_resp; /* failed connect() and responses */
unsigned failed_secu; /* blocked responses because of security concerns */
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 */
struct proxy *proxy; /* the proxy this server belongs to */
};

View File

@ -154,7 +154,8 @@ struct session {
char *cli_cookie; /* cookie presented by the client, in capture mode */
char *srv_cookie; /* cookie presented by the server, in capture mode */
int status; /* HTTP status from the server, negative if from proxy */
long long bytes; /* number of bytes transferred from the server */
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 */
} logs;
short int data_source; /* where to get the data we generate ourselves */
short int data_state; /* where to get the data we generate ourselves */

View File

@ -35,6 +35,7 @@ int buffer_write(struct buffer *buf, const char *msg, int len)
memcpy(buf->r, msg, len);
buf->l += len;
buf->r += len;
buf->total += len;
if (buf->r == buf->data + BUFSIZE)
buf->r = buf->data;
return 0;
@ -59,6 +60,7 @@ int buffer_write_chunk(struct buffer *buf, struct chunk *chunk)
memcpy(buf->r, chunk->str, chunk->len);
buf->l += chunk->len;
buf->r += chunk->len;
buf->total += chunk->len;
if (buf->r == buf->data + BUFSIZE)
buf->r = buf->data;
chunk->len = 0;

View File

@ -188,7 +188,7 @@ int event_accept(int fd) {
s->logs.cli_cookie = NULL;
s->logs.srv_cookie = NULL;
s->logs.status = -1;
s->logs.bytes = 0;
s->logs.bytes_in = s->logs.bytes_out = 0;
s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
s->logs.srv_queue_size = 0; /* we will get this number soon */

View File

@ -396,7 +396,7 @@ void sess_log(struct session *s)
(s->logs.t_data >= 0) ? s->logs.t_data - s->logs.t_connect : -1,
(tolog & LW_BYTES) ? "" : "+", s->logs.t_close,
s->logs.status,
(tolog & LW_BYTES) ? "" : "+", s->logs.bytes,
(tolog & LW_BYTES) ? "" : "+", s->logs.bytes_in,
s->logs.cli_cookie ? s->logs.cli_cookie : "-",
s->logs.srv_cookie ? s->logs.srv_cookie : "-",
sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT],
@ -420,7 +420,7 @@ void sess_log(struct session *s)
(s->logs.t_queue >= 0) ? s->logs.t_queue : -1,
(s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1,
(tolog & LW_BYTES) ? "" : "+", s->logs.t_close,
(tolog & LW_BYTES) ? "" : "+", s->logs.bytes,
(tolog & LW_BYTES) ? "" : "+", s->logs.bytes_in,
sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT],
sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT],
actconn, fe->feconn, be->beprm->beconn, s->srv ? s->srv->cur_sess : 0,

View File

@ -396,8 +396,21 @@ int process_session(struct task *t)
}
s->logs.t_close = tv_diff(&s->logs.tv_accept, &now);
if (s->req != NULL)
s->logs.bytes_in = s->req->total;
if (s->rep != NULL)
s->logs.bytes = s->rep->total;
s->logs.bytes_out = s->rep->total;
s->fe->bytes_in += s->logs.bytes_in;
s->fe->bytes_out += s->logs.bytes_out;
if (s->be->beprm != s->fe) {
s->be->beprm->bytes_in += s->logs.bytes_in;
s->be->beprm->bytes_out += s->logs.bytes_out;
}
if (s->srv) {
s->srv->bytes_in += s->logs.bytes_in;
s->srv->bytes_out += s->logs.bytes_out;
}
/* let's do a final log if we need it */
if (s->logs.logwait &&
@ -1947,7 +1960,7 @@ int process_srv(struct session *t)
bytes from the server, then this is the right moment. */
if (t->fe->to_log && !(t->logs.logwait & LW_BYTES)) {
t->logs.t_close = t->logs.t_data; /* to get a valid end date */
t->logs.bytes = rep->h - rep->data;
t->logs.bytes_in = rep->h - rep->data;
sess_log(t);
}
break;
@ -2860,7 +2873,7 @@ int produce_content_stats(struct session *s)
".backup3 {background: #b0d0ff;}\n"
".backup4 {background: #e0e0e0;}\n"
"table.tbl { border-collapse: collapse; border-style: none;}\n"
"table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; border-color: gray;}\n"
"table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n"
"table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
"table.tbl th.empty { border-style: none; empty-cells: hide;}\n"
"table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
@ -3042,8 +3055,8 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
"<th colspan=3>Errors</th><th colspan=6>Server</th>"
"</tr>\n"
"<tr align=\"center\" class=\"titre\">"
"<th>Curr.</th><th>Max.</th><th>Curr.</th><th>Max.</th>"
"<th>Limit</th><th>Cumul.</th><th>In</th><th>Out</th>"
"<th>Cur</th><th>Max</th><th>Cur</th><th>Max</th>"
"<th>Limit</th><th>Cumul</th><th>In</th><th>Out</th>"
"<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
"<th>Resp</th><th>Status</th><th>Weight</th><th>Act</th>"
"<th>Bck</th><th>Check</th><th>Down</th></tr>\n"
@ -3065,7 +3078,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
/* sessions : current, max, limit, cumul. */
"<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>"
/* bytes : in, out */
"<td align=right></td><td align=right></td>"
"<td align=right>%lld</td><td align=right>%lld</td>"
/* denied: req, resp */
"<td align=right>%d</td><td align=right>%d</td>"
/* errors : request, connect, response */
@ -3076,6 +3089,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
"<td align=center colspan=5></td></tr>"
"",
px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
px->bytes_in, px->bytes_out,
px->denied_req, px->denied_resp,
px->failed_req,
px->state == PR_STRUN ? "OPEN" :
@ -3119,7 +3133,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
/* sessions : current, max, limit, cumul */
"<td align=right>%d</td><td align=right>%d</td><td align=right>%s</td><td align=right>%d</td>"
/* bytes : in, out */
"<td align=right></td><td align=right></td>"
"<td align=right>%lld</td><td align=right>%lld</td>"
/* denied: req, resp */
"<td align=right></td><td align=right>%d</td>"
/* errors : request, connect, response */
@ -3129,6 +3143,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
sv_state, sv->id,
sv->nbpend, sv->nbpend_max,
sv->cur_sess, sv->cur_sess_max, sv->maxconn ? ultoa(sv->maxconn) : "-", sv->cum_sess,
sv->bytes_in, sv->bytes_out,
sv->failed_secu,
sv->failed_conns, sv->failed_resp);
@ -3178,7 +3193,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
/* sessions : current, max, limit, cumul. */
"<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>"
/* bytes : in, out */
"<td align=right></td><td align=right></td>"
"<td align=right>%lld</td><td align=right>%lld</td>"
/* denied: req, resp */
"<td align=right>%d</td><td align=right>%d</td>"
/* errors : request, connect, response */
@ -3194,6 +3209,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
"",
px->nbpend /* or px->totpend ? */, px->nbpend_max,
px->beconn, px->beconn_max, px->fullconn, px->cum_beconn,
px->bytes_in, px->bytes_out,
px->denied_req, px->denied_resp,
px->failed_conns, px->failed_resp,
(px->srv_map_sz > 0 || !px->srv) ? "UP" : "DOWN",