[MINOR] stats: factorize many chunk_printf()

Improve code size, speed and readability by factoring many
calls to chunk_printf().
This commit is contained in:
Willy Tarreau 2007-01-01 22:01:43 +01:00
parent c0dde7a8ed
commit 128e954663

View File

@ -3047,37 +3047,28 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
case DATA_ST_PX_FE: case DATA_ST_PX_FE:
/* print the frontend */ /* print the frontend */
if (px->cap & PR_CAP_FE) { if (px->cap & PR_CAP_FE) {
/* name, queue */
chunk_printf(&msg, sizeof(trash), chunk_printf(&msg, sizeof(trash),
"<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=2></td>"); /* name, queue */
"<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=2></td>"
/* sessions : current, max, limit, cumul. */ /* sessions : current, max, limit, cumul. */
chunk_printf(&msg, sizeof(trash), "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>"
"<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>", /* bytes : in, out */
px->feconn, px->feconn_max, px->maxconn, px->cum_feconn); "<td align=right></td><td align=right></td>"
/* denied: req, resp */
/* bytes : in, out */ "<td align=right>%d</td><td align=right>%d</td>"
chunk_printf(&msg, sizeof(trash), /* errors : request, connect, response */
"<td align=right></td><td align=right></td>"); "<td align=right>%d</td><td align=right></td><td align=right></td>"
/* server status : reflect backend status */
/* denied: req, resp */ "<td align=center>%s</td>"
chunk_printf(&msg, sizeof(trash), /* rest of server: nothing */
"<td align=right>%d</td><td align=right>%d</td>", "<td align=center colspan=5></td></tr>"
px->denied_req, px->denied_resp); "",
px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
/* errors : request, connect, response */ px->denied_req, px->denied_resp,
chunk_printf(&msg, sizeof(trash), px->failed_req,
"<td align=right>%d</td><td align=right></td><td align=right></td>",
px->failed_req);
/* server status : reflect backend status */
chunk_printf(&msg, sizeof(trash), "<td align=center>%s</td>",
px->state == PR_STRUN ? "OPEN" : px->state == PR_STRUN ? "OPEN" :
px->state == PR_STIDLE ? "FULL" : "STOP"); px->state == PR_STIDLE ? "FULL" : "STOP");
/* rest of server: nothing */
chunk_printf(&msg, sizeof(trash), "<td align=center colspan=5></td></tr>");
if (buffer_write_chunk(rep, &msg) != 0) if (buffer_write_chunk(rep, &msg) != 0)
return 0; return 0;
} }
@ -3108,34 +3099,25 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
else else
sv_state = 0; /* DOWN */ sv_state = 0; /* DOWN */
/* name */
chunk_printf(&msg, sizeof(trash), chunk_printf(&msg, sizeof(trash),
"<tr align=\"center\" class=\"%s%d\"><td>%s</td>", /* name */
"<tr align=\"center\" class=\"%s%d\"><td>%s</td>"
/* queue : current, max */
"<td align=right>%d</td><td align=right>%d</td>"
/* 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>"
/* denied: req, resp */
"<td align=right></td><td align=right>%d</td>"
/* errors : request, connect, response */
"<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n"
"",
(sv->state & SRV_BACKUP) ? "active" : "backup", (sv->state & SRV_BACKUP) ? "active" : "backup",
sv_state, sv->id); sv_state, sv->id,
sv->nbpend, sv->nbpend_max,
/* queue : current, max */ sv->cur_sess, sv->cur_sess_max, sv->maxconn ? ultoa(sv->maxconn) : "-", sv->cum_sess,
chunk_printf(&msg, sizeof(trash), sv->failed_secu,
"<td align=right>%d</td><td align=right>%d</td>",
sv->nbpend, sv->nbpend_max);
/* sessions : current, max, limit, cumul */
chunk_printf(&msg, sizeof(trash),
"<td align=right>%d</td><td align=right>%d</td><td align=right>%s</td><td align=right>%d</td>",
sv->cur_sess, sv->cur_sess_max, sv->maxconn ? ultoa(sv->maxconn) : "-", sv->cum_sess);
/* bytes : in, out */
chunk_printf(&msg, sizeof(trash),
"<td align=right></td><td align=right></td>");
/* denied: req, resp */
chunk_printf(&msg, sizeof(trash),
"<td align=right></td><td align=right>%d</td>",
sv->failed_secu);
/* errors : request, connect, response */
chunk_printf(&msg, sizeof(trash),
"<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n",
sv->failed_conns, sv->failed_resp); sv->failed_conns, sv->failed_resp);
/* status */ /* status */
@ -3145,11 +3127,13 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
(sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
(sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
/* weight */ chunk_printf(&msg, sizeof(trash),
chunk_printf(&msg, sizeof(trash), "<td>%d</td>", sv->uweight+1); /* weight */
"</td><td>%d</td>"
/* act, bck */ /* act, bck */
chunk_printf(&msg, sizeof(trash), "<td>%s</td><td>%s</td>", "<td>%s</td><td>%s</td>"
"",
sv->uweight+1,
(sv->state & SRV_BACKUP) ? "-" : "Y", (sv->state & SRV_BACKUP) ? "-" : "Y",
(sv->state & SRV_BACKUP) ? "Y" : "-"); (sv->state & SRV_BACKUP) ? "Y" : "-");
@ -3174,48 +3158,35 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
case DATA_ST_PX_BE: case DATA_ST_PX_BE:
/* print the backend */ /* print the backend */
if (px->cap & PR_CAP_BE) { if (px->cap & PR_CAP_BE) {
/* name */
chunk_printf(&msg, sizeof(trash), chunk_printf(&msg, sizeof(trash),
"<tr align=center class=\"backend\"><td>Backend</td>"); /* name */
"<tr align=center class=\"backend\"><td>Backend</td>"
/* queue : current, max */ /* queue : current, max */
chunk_printf(&msg, sizeof(trash), "<td align=right>%d</td><td align=right>%d</td>"
"<td align=right>%d</td><td align=right>%d</td>", /* sessions : current, max, limit, cumul. */
px->nbpend /* or px->totpend ? */, px->nbpend_max); "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>"
/* bytes : in, out */
/* sessions : current, max, limit, cumul. */ "<td align=right></td><td align=right></td>"
chunk_printf(&msg, sizeof(trash), /* denied: req, resp */
"<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>", "<td align=right>%d</td><td align=right>%d</td>"
px->beconn, px->beconn_max, px->fullconn, px->cum_beconn); /* errors : request, connect, response */
"<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n"
/* bytes : in, out */ /* server status : reflect backend status (up/down) : we display UP
chunk_printf(&msg, sizeof(trash), * if the backend has known working servers or if it has no server at
"<td align=right></td><td align=right></td>"); * all (eg: for stats). Tthen we display the total weight, number of
* active and backups. */
/* denied: req, resp */ "<td align=center>%s</td><td align=center>%d</td>"
chunk_printf(&msg, sizeof(trash), "<td align=center>%d</td><td align=center>%d</td>"
"<td align=right>%d</td><td align=right>%d</td>", /* rest of server: nothing */
px->denied_req, px->denied_resp); "<td align=center colspan=2></td></tr>"
"",
/* errors : request, connect, response */ px->nbpend /* or px->totpend ? */, px->nbpend_max,
chunk_printf(&msg, sizeof(trash), px->beconn, px->beconn_max, px->fullconn, px->cum_beconn,
"<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n", px->denied_req, px->denied_resp,
px->failed_conns, px->failed_resp); px->failed_conns, px->failed_resp,
/* server status : reflect backend status (up/down) : we display UP
* if the backend has known working servers or if it has no server at
* all (eg: for stats). Tthen we display the total weight, number of
* active and backups. */
chunk_printf(&msg, sizeof(trash),
"<td align=center>%s</td>"
"<td align=center>%d</td>"
"<td align=center>%d</td><td align=center>%d</td>",
(px->srv_map_sz > 0 || !px->srv) ? "UP" : "DOWN", (px->srv_map_sz > 0 || !px->srv) ? "UP" : "DOWN",
px->srv_map_sz, px->srv_act, px->srv_bck); px->srv_map_sz, px->srv_act, px->srv_bck);
/* rest of server: nothing */
chunk_printf(&msg, sizeof(trash), "<td align=center colspan=2></td></tr>");
if (buffer_write_chunk(rep, &msg) != 0) if (buffer_write_chunk(rep, &msg) != 0)
return 0; return 0;
} }