MINOR: stats: add stats size as a parameter for csv/json dump
Render the stats size parametric in csv/json dump functions. This is
needed for the future patch which provides dynamic stats. For now the
static value ST_F_TOTAL_FIELDS is provided.
Remove unused parameter px on stats_dump_one_line.
This patch is needed to extend stat support to components other than
proxies objects.
diff --git a/include/haproxy/stats.h b/include/haproxy/stats.h
index 3c53486..4fe96b5 100644
--- a/include/haproxy/stats.h
+++ b/include/haproxy/stats.h
@@ -42,7 +42,7 @@
struct htx;
int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk);
-int stats_dump_one_line(const struct field *stats, struct proxy *px, struct appctx *appctx);
+int stats_dump_one_line(const struct field *stats, size_t stats_count, struct appctx *appctx);
int stats_fill_info(struct field *info, int len);
int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len);
diff --git a/src/stats.c b/src/stats.c
index 9b2e911..6ba3f62 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -512,11 +512,12 @@
/* Dump all fields from <stats> into <out> using CSV format */
static int stats_dump_fields_csv(struct buffer *out,
- const struct field *stats, unsigned int flags)
+ const struct field *stats, size_t stats_count,
+ unsigned int flags)
{
int field;
- for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
+ for (field = 0; field < stats_count; field++) {
if (!stats_emit_raw_data_field(out, &stats[field]))
return 0;
if (!chunk_strcat(out, ","))
@@ -528,11 +529,13 @@
/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
static int stats_dump_fields_typed(struct buffer *out,
- const struct field *stats, unsigned int flags)
+ const struct field *stats,
+ size_t stats_count,
+ unsigned int flags)
{
int field;
- for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
+ for (field = 0; field < stats_count; ++field) {
if (!stats[field].type)
continue;
@@ -608,8 +611,8 @@
/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
static int stats_dump_fields_json(struct buffer *out,
- const struct field *stats,
- unsigned int flags)
+ const struct field *stats, size_t stats_count,
+ unsigned int flags)
{
int field;
int started = 0;
@@ -619,7 +622,7 @@
if (!chunk_strcat(out, "["))
return 0;
- for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
+ for (field = 0; field < stats_count; field++) {
const char *obj_type;
int old_len;
@@ -1381,18 +1384,19 @@
return 1;
}
-int stats_dump_one_line(const struct field *stats, struct proxy *px, struct appctx *appctx)
+int stats_dump_one_line(const struct field *stats, size_t stats_count,
+ struct appctx *appctx)
{
int ret;
if (appctx->ctx.stats.flags & STAT_FMT_HTML)
ret = stats_dump_fields_html(&trash, stats, appctx->ctx.stats.flags);
else if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
- ret = stats_dump_fields_typed(&trash, stats, appctx->ctx.stats.flags);
+ ret = stats_dump_fields_typed(&trash, stats, stats_count, appctx->ctx.stats.flags);
else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
- ret = stats_dump_fields_json(&trash, stats, appctx->ctx.stats.flags);
+ ret = stats_dump_fields_json(&trash, stats, stats_count, appctx->ctx.stats.flags);
else
- ret = stats_dump_fields_csv(&trash, stats, appctx->ctx.stats.flags);
+ ret = stats_dump_fields_csv(&trash, stats, stats_count, appctx->ctx.stats.flags);
if (ret)
appctx->ctx.stats.flags |= STAT_STARTED;
@@ -1486,7 +1490,7 @@
if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS))
return 0;
- return stats_dump_one_line(stats, px, appctx);
+ return stats_dump_one_line(stats, ST_F_TOTAL_FIELDS, appctx);
}
/* Fill <stats> with the listener statistics. <stats> is
@@ -1571,7 +1575,7 @@
if (!stats_fill_li_stats(px, l, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
return 0;
- return stats_dump_one_line(stats, px, appctx);
+ return stats_dump_one_line(stats, ST_F_TOTAL_FIELDS, appctx);
}
enum srv_stats_state {
@@ -1878,7 +1882,7 @@
if (!stats_fill_sv_stats(px, sv, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
return 0;
- return stats_dump_one_line(stats, px, appctx);
+ return stats_dump_one_line(stats, ST_F_TOTAL_FIELDS, appctx);
}
/* Fill <stats> with the backend statistics. <stats> is
@@ -1998,7 +2002,7 @@
if (!stats_fill_be_stats(px, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
return 0;
- return stats_dump_one_line(stats, px, appctx);
+ return stats_dump_one_line(stats, ST_F_TOTAL_FIELDS, appctx);
}
/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from