From 501f60244f0f5c304804c6085e28d3d35b7d51a3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 8 Jan 2016 17:37:22 +0100 Subject: [PATCH] MINOR: stats: introduce stats_dump_one_line() to dump one stats line This new function dumps the current stats line according to the specified format (CSV or HTML for now), and returns these functions' output code, which will serve later to indicate a failure (eg: buffer full). This further simplifies the code since all dumpers now just call this function. --- src/dumpstats.c | 60 +++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/src/dumpstats.c b/src/dumpstats.c index 6d088ce6d..64d60b069 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -3897,6 +3897,18 @@ static int stats_dump_fields_html(const struct field *stats, int admin, unsigned return 1; } +static int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) +{ + int admin; + + admin = (px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN); + + if (appctx->ctx.stats.flags & STAT_FMT_HTML) + return stats_dump_fields_html(stats, admin, flags, px); + else + return stats_dump_fields_csv(&trash, stats); +} + /* Dumps a frontend's line to the trash for the current proxy and uses * the state from stream interface . The caller is responsible for clearing * the trash if needed. Returns non-zero if it emits anything, zero otherwise. @@ -3961,17 +3973,7 @@ static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); - if (appctx->ctx.stats.flags & STAT_FMT_HTML) { - int admin; - - admin = (px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN); - stats_dump_fields_html(stats, admin, 0, px); - } - else { /* CSV mode */ - /* dump everything */ - stats_dump_fields_csv(&trash, stats); - } - return 1; + return stats_dump_one_line(stats, 0, px, appctx); } /* Dumps a line for listener and proxy to the trash and uses the state @@ -4031,17 +4033,7 @@ static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, st } } - if (appctx->ctx.stats.flags & STAT_FMT_HTML) { - int admin; - - admin = (px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN); - stats_dump_fields_html(stats, admin, flags, px); - } - else { /* CSV mode */ - /* dump everything */ - stats_dump_fields_csv(&trash, stats); - } - return 1; + return stats_dump_one_line(stats, flags, px, appctx); } enum srv_stats_state { @@ -4300,17 +4292,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); } - if (appctx->ctx.stats.flags & STAT_FMT_HTML) { - int admin; - - admin = (px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN); - stats_dump_fields_html(stats, admin, flags, px); - } - else { /* CSV mode */ - /* dump everything */ - stats_dump_fields_csv(&trash, stats); - } - return 1; + return stats_dump_one_line(stats, flags, px, appctx); } /* Dumps a line for backend to the trash for and uses the state from stream @@ -4396,17 +4378,7 @@ static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, in stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); - if (appctx->ctx.stats.flags & STAT_FMT_HTML) { - int admin; - - admin = (px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN); - stats_dump_fields_html(stats, admin, flags, px); - } - else { /* CSV mode */ - /* dump everything */ - stats_dump_fields_csv(&trash, stats); - } - return 1; + return stats_dump_one_line(stats, flags, px, appctx); } /* Dumps the HTML table header for proxy to the trash for and uses the state from