From: Willy Tarreau Date: Mon, 11 Jan 2016 14:32:30 +0000 (+0100) Subject: MINOR: stats: make stats_dump_fields_html() not use &trash by default X-Git-Tag: v1.7-dev2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6060074a574686325faf4130c78283c39b50956f;p=thirdparty%2Fhaproxy.git MINOR: stats: make stats_dump_fields_html() not use &trash by default This function must dump into the buffer it gets in argument, and should not assume it's always trash. This was the last part of the rework, now the CSV and HTML functions are compatible and the output format may easily be extended. --- diff --git a/src/dumpstats.c b/src/dumpstats.c index 0bcead6819..4f3efa675e 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -3260,25 +3260,25 @@ static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) return 1; } -/* Dump all fields from into trash using the HTML format. A column is +/* Dump all fields from into using the HTML format. A column is * reserved for the checkbox is ST_SHOWADMIN is set in . Some extra info * are provided if ST_SHLGNDS is present in . */ -static int stats_dump_fields_html(const struct field *stats, unsigned int flags) +static int stats_dump_fields_html(struct chunk *out, const struct field *stats, unsigned int flags) { struct chunk src; if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { - chunk_appendf(&trash, + chunk_appendf(out, /* name, queue */ ""); if (flags & ST_SHOWADMIN) { /* Column sub-heading for Enable or Disable server */ - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); } - chunk_appendf(&trash, + chunk_appendf(out, "" "" "Frontend" @@ -3286,7 +3286,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) "", field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); - chunk_appendf(&trash, + chunk_appendf(out, /* sessions rate : current */ "%s
" "" @@ -3297,11 +3297,11 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_RATE].u.u32)); if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) - chunk_appendf(&trash, + chunk_appendf(out, "", U2H(stats[ST_F_REQ_RATE].u.u32)); - chunk_appendf(&trash, + chunk_appendf(out, "
Current connection rate:%s/s
Current request rate:%s/s
" /* sessions rate : max */ "%s
" @@ -3313,17 +3313,17 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_RATE_MAX].u.u32)); if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) - chunk_appendf(&trash, + chunk_appendf(out, "", U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); - chunk_appendf(&trash, + chunk_appendf(out, "
Max request rate:%s/s
" /* sessions rate : limit */ "%s", LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); - chunk_appendf(&trash, + chunk_appendf(out, /* sessions: current, max, limit, total */ "%s%s%s" "%s
" @@ -3337,7 +3337,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { - chunk_appendf(&trash, + chunk_appendf(out, "" "" "" @@ -3361,7 +3361,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_INTERCEPTED].u.u64)); } - chunk_appendf(&trash, + chunk_appendf(out, "
Cum. HTTP requests:%s
- HTTP 1xx responses:%s
- HTTP 2xx responses:%s
" /* sessions: lbtot, lastsess */ "" @@ -3370,7 +3370,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) "", U2H(stats[ST_F_BIN].u.u64)); - chunk_appendf(&trash, + chunk_appendf(out, /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ "%s%s
" "" @@ -3390,7 +3390,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "":""); - chunk_appendf(&trash, + chunk_appendf(out, /* denied: req, resp */ "" /* errors : request, connect, response */ @@ -3407,13 +3407,13 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) field_str(stats, ST_F_STATUS)); } else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); if (flags & ST_SHOWADMIN) { /* Column sub-heading for Enable or Disable server */ - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); } - chunk_appendf(&trash, + chunk_appendf(out, /* frontend name, listener name */ "" /* sessions rate: current, max, limit */ @@ -3451,7 +3451,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); - chunk_appendf(&trash, + chunk_appendf(out, /* denied: req, resp */ "" /* errors: request, connect, response */ @@ -3506,19 +3506,19 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) } if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); else - chunk_appendf(&trash, + chunk_appendf(out, "", (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); if (flags & ST_SHOWADMIN) - chunk_appendf(&trash, + chunk_appendf(out, "", field_str(stats, ST_F_SVNAME)); - chunk_appendf(&trash, + chunk_appendf(out, "" /* sessions rate : current, max, limit */ @@ -3560,7 +3560,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); - chunk_appendf(&trash, + chunk_appendf(out, /* sessions: current, max, limit, total */ "" "" /* sessions: lbtot, last */ "", U2H(stats[ST_F_LBTOT].u.u64), human_time(stats[ST_F_LASTSESS].u.s32, 1)); - chunk_appendf(&trash, + chunk_appendf(out, /* bytes : in, out */ "" /* denied: req, resp */ @@ -3635,7 +3635,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) (long long)stats[ST_F_WREDIS].u.u64); /* status, last change */ - chunk_appendf(&trash, "" /* act, bck */ @@ -3716,12 +3716,12 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) /* check failures: unique, fatal, down time */ if (stats[ST_F_CHKFAIL].type) { - chunk_appendf(&trash, "" "" "", @@ -3730,26 +3730,26 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) } else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ - chunk_appendf(&trash, + chunk_appendf(out, "", field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); } else - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); /* throttle */ if (stats[ST_F_THROTTLE].type) - chunk_appendf(&trash, "\n", stats[ST_F_THROTTLE].u.u32); + chunk_appendf(out, "\n", stats[ST_F_THROTTLE].u.u32); else - chunk_appendf(&trash, "\n"); + chunk_appendf(out, "\n"); } else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); if (flags & ST_SHOWADMIN) { /* Column sub-heading for Enable or Disable server */ - chunk_appendf(&trash, ""); + chunk_appendf(out, ""); } - chunk_appendf(&trash, + chunk_appendf(out, "" /* queue : current, max */ "" @@ -3784,7 +3784,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); - chunk_appendf(&trash, + chunk_appendf(out, /* sessions: current, max, limit, total */ "" "" /* sessions: lbtot, last */ "" @@ -3838,7 +3838,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) human_time(stats[ST_F_LASTSESS].u.s32, 1), U2H(stats[ST_F_BIN].u.u64)); - chunk_appendf(&trash, + chunk_appendf(out, /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ "
Response bytes in:%s
%s%s
%s" "%s" @@ -3423,20 +3423,20 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); if (flags & ST_SHLGNDS) { - chunk_appendf(&trash, "
"); + chunk_appendf(out, "
"); if (isdigit(*field_str(stats, ST_F_ADDR))) - chunk_appendf(&trash, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); + chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); else if (*field_str(stats, ST_F_ADDR) == '[') - chunk_appendf(&trash, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); + chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); else if (*field_str(stats, ST_F_ADDR)) - chunk_appendf(&trash, "%s, ", field_str(stats, ST_F_ADDR)); + chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); /* id */ - chunk_appendf(&trash, "id: %d
", stats[ST_F_SID].u.u32); + chunk_appendf(out, "id: %d
", stats[ST_F_SID].u.u32); } - chunk_appendf(&trash, + chunk_appendf(out, /* queue */ "%s
%s%s
%s" "%s" "", @@ -3527,30 +3527,30 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); if (flags & ST_SHLGNDS) { - chunk_appendf(&trash, "
"); + chunk_appendf(out, "
"); if (isdigit(*field_str(stats, ST_F_ADDR))) - chunk_appendf(&trash, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); + chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); else if (*field_str(stats, ST_F_ADDR) == '[') - chunk_appendf(&trash, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); + chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); else if (*field_str(stats, ST_F_ADDR)) - chunk_appendf(&trash, "%s, ", field_str(stats, ST_F_ADDR)); + chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); /* id */ - chunk_appendf(&trash, "id: %d", stats[ST_F_SID].u.u32); + chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); /* cookie */ if (stats[ST_F_COOKIE].type) { - chunk_appendf(&trash, ", cookie: '"); + chunk_appendf(out, ", cookie: '"); chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); - chunk_htmlencode(&trash, &src); - chunk_appendf(&trash, "'"); + chunk_htmlencode(out, &src); + chunk_appendf(out, "'"); } - chunk_appendf(&trash, "
"); + chunk_appendf(out, "
"); } - chunk_appendf(&trash, + chunk_appendf(out, /* queue : current, max, limit */ "%s
%s%s%s%s%s%s%s
" @@ -3581,7 +3581,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) tot += stats[ST_F_HRSP_4XX].u.u64; tot += stats[ST_F_HRSP_5XX].u.u64; - chunk_appendf(&trash, + chunk_appendf(out, "" "" "" @@ -3599,21 +3599,21 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0); } - chunk_appendf(&trash, ""); - chunk_appendf(&trash, "", U2H(stats[ST_F_QTIME].u.u32)); - chunk_appendf(&trash, "", U2H(stats[ST_F_CTIME].u.u32)); + chunk_appendf(out, ""); + chunk_appendf(out, "", U2H(stats[ST_F_QTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_CTIME].u.u32)); if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) - chunk_appendf(&trash, "", U2H(stats[ST_F_RTIME].u.u32)); - chunk_appendf(&trash, "", U2H(stats[ST_F_TTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_RTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_TTIME].u.u32)); - chunk_appendf(&trash, + chunk_appendf(out, "
Cum. HTTP responses:%s
- HTTP 1xx responses:%s(%d%%)
- HTTP 2xx responses:%s(%d%%)
Avg over last 1024 success. conn.
- Queue time:%sms
- Connect time:%sms
Avg over last 1024 success. conn.
- Queue time:%sms
- Connect time:%sms
- Response time:%sms
- Total time:%sms
- Response time:%sms
- Total time:%sms
%s%s%s%s"); + chunk_appendf(out, ""); /* FIXME!!!! * LASTCHG should contain the last change for *this* server and must be computed @@ -3645,66 +3645,66 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { - chunk_appendf(&trash, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); + chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); } else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) { - chunk_strcat(&trash, "no check"); + chunk_strcat(out, "no check"); } else { - chunk_appendf(&trash, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); + chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { if (stats[ST_F_CHECK_HEALTH].u.u32) - chunk_strcat(&trash, " ↑"); + chunk_strcat(out, " ↑"); } else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) - chunk_strcat(&trash, " ↓"); + chunk_strcat(out, " ↓"); } if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { - chunk_appendf(&trash, + chunk_appendf(out, " %s", field_str(stats, ST_F_AGENT_STATUS)); if (stats[ST_F_AGENT_CODE].type) - chunk_appendf(&trash, "/%d", stats[ST_F_AGENT_CODE].u.u32); + chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); if (stats[ST_F_AGENT_DURATION].type && stats[ST_F_AGENT_DURATION].u.u64 >= 0) - chunk_appendf(&trash, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); + chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); - chunk_appendf(&trash, "
%s", field_str(stats, ST_F_AGENT_DESC)); + chunk_appendf(out, "
%s", field_str(stats, ST_F_AGENT_DESC)); if (*field_str(stats, ST_F_LAST_AGT)) { - chunk_appendf(&trash, ": "); + chunk_appendf(out, ": "); chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); - chunk_htmlencode(&trash, &src); + chunk_htmlencode(out, &src); } - chunk_appendf(&trash, "
"); + chunk_appendf(out, "
"); } else if (stats[ST_F_CHECK_STATUS].type) { - chunk_appendf(&trash, + chunk_appendf(out, "
%s", field_str(stats, ST_F_CHECK_STATUS)); if (stats[ST_F_CHECK_CODE].type) - chunk_appendf(&trash, "/%d", stats[ST_F_CHECK_CODE].u.u32); + chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); if (stats[ST_F_CHECK_DURATION].type && stats[ST_F_CHECK_DURATION].u.u64 >= 0) - chunk_appendf(&trash, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); + chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); - chunk_appendf(&trash, "
%s", field_str(stats, ST_F_CHECK_DESC)); + chunk_appendf(out, "
%s", field_str(stats, ST_F_CHECK_DESC)); if (*field_str(stats, ST_F_LAST_CHK)) { - chunk_appendf(&trash, ": "); + chunk_appendf(out, ": "); chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); - chunk_htmlencode(&trash, &src); + chunk_htmlencode(out, &src); } - chunk_appendf(&trash, "
"); + chunk_appendf(out, "
"); } else - chunk_appendf(&trash, "
"); + chunk_appendf(out, ""); - chunk_appendf(&trash, + chunk_appendf(out, /* weight */ "%d%lld", (long long)stats[ST_F_CHKFAIL].u.u64); + chunk_appendf(out, "%lld", (long long)stats[ST_F_CHKFAIL].u.u64); if (stats[ST_F_HANAFAIL].type) - chunk_appendf(&trash, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); + chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); - chunk_appendf(&trash, + chunk_appendf(out, "
Failed Health Checks%s
%lld%svia %s%d %%
%d %%
-
-
" /* name */ "%s" @@ -3760,20 +3760,20 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) if (flags & ST_SHLGNDS) { /* balancing */ - chunk_appendf(&trash, "
balancing: %s", + chunk_appendf(out, "
balancing: %s", field_str(stats, ST_F_ALGO)); /* cookie */ if (stats[ST_F_COOKIE].type) { - chunk_appendf(&trash, ", cookie: '"); + chunk_appendf(out, ", cookie: '"); chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); - chunk_htmlencode(&trash, &src); - chunk_appendf(&trash, "'"); + chunk_htmlencode(out, &src); + chunk_appendf(out, "'"); } - chunk_appendf(&trash, "
"); + chunk_appendf(out, "
"); } - chunk_appendf(&trash, + chunk_appendf(out, "%s
%s%s%s%s%s%s
" @@ -3796,7 +3796,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { - chunk_appendf(&trash, + chunk_appendf(out, "" "" "" @@ -3821,13 +3821,13 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) U2H(stats[ST_F_INTERCEPTED].u.u64)); } - chunk_appendf(&trash, "", U2H(stats[ST_F_QTIME].u.u32)); - chunk_appendf(&trash, "", U2H(stats[ST_F_QTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_QTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_QTIME].u.u32)); if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) - chunk_appendf(&trash, "", U2H(stats[ST_F_RTIME].u.u32)); - chunk_appendf(&trash, "", U2H(stats[ST_F_TTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_RTIME].u.u32)); + chunk_appendf(out, "", U2H(stats[ST_F_TTIME].u.u32)); - chunk_appendf(&trash, + chunk_appendf(out, "
Cum. HTTP requests:%s
- HTTP 1xx responses:%s
- HTTP 2xx responses:%s
- Queue time:%sms
- Connect time:%sms
- Queue time:%sms
- Connect time:%sms
- Response time:%sms
- Total time:%sms
- Response time:%sms
- Total time:%sms
%s%s%s%s
" "" @@ -3858,7 +3858,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "":""); - chunk_appendf(&trash, + chunk_appendf(out, /* denied: req, resp */ "" /* errors : request, connect */ @@ -3885,7 +3885,7 @@ static int stats_dump_fields_html(const struct field *stats, unsigned int flags) stats[ST_F_WEIGHT].u.u32, stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); - chunk_appendf(&trash, + chunk_appendf(out, /* rest of backend: nothing, down transitions, total downtime, throttle */ "" "" @@ -3903,7 +3903,7 @@ static int stats_dump_one_line(const struct field *stats, unsigned int flags, st flags |= ST_SHOWADMIN; if (appctx->ctx.stats.flags & STAT_FMT_HTML) - return stats_dump_fields_html(stats, flags); + return stats_dump_fields_html(&trash, stats, flags); else return stats_dump_fields_csv(&trash, stats); }
Response bytes in:%s
%s%s %d%s