MINOR: dumpstats: split stats_dump_info_to_buffer() in two parts
This patch splits the function stats_dump_info_to_buffer() in two parts. The
extracted part is called stats_fill_info(), and just fill the stats buffer.
This split allows the usage of preformated stats in other parts of HAProxy
like the Lua.
diff --git a/include/proto/dumpstats.h b/include/proto/dumpstats.h
index 9db2eec..ac0c0b5 100644
--- a/include/proto/dumpstats.h
+++ b/include/proto/dumpstats.h
@@ -391,6 +391,8 @@
extern const char *info_field_names[];
extern const char *stat_field_names[];
+int stats_fill_info(struct field *info, int len);
+
extern struct applet http_stats_applet;
void stats_io_handler(struct stream_interface *si);
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 833dd9f..0474eab 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -2948,15 +2948,15 @@
return 1;
}
-/* This function dumps information onto the stream interface's read buffer.
- * It returns 0 as long as it does not complete, non-zero upon completion.
- * No state is used.
+/* Fill <info> with HAProxy global info. <info> is preallocated
+ * array of length <len>. The length of the aray must be
+ * INF_TOTAL_FIELDS. If this length is less then this value, the
+ * function returns 0, otherwise, it returns 1.
*/
-static int stats_dump_info_to_buffer(struct stream_interface *si)
+int stats_fill_info(struct field *info, int len)
{
unsigned int up = (now.tv_sec - start_date.tv_sec);
struct chunk *out = get_trash_chunk();
- struct appctx *appctx = __objt_appctx(si->end);
#ifdef USE_OPENSSL
int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
@@ -2969,8 +2969,11 @@
}
#endif
+ if (len < INF_TOTAL_FIELDS)
+ return 0;
+
chunk_reset(out);
- memset(&info, 0, sizeof(info));
+ memset(info, 0, sizeof(*info) * len);
info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME);
info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION);
@@ -3036,6 +3039,20 @@
if (global.desc)
info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
+ return 1;
+}
+
+/* This function dumps information onto the stream interface's read buffer.
+ * It returns 0 as long as it does not complete, non-zero upon completion.
+ * No state is used.
+ */
+static int stats_dump_info_to_buffer(struct stream_interface *si)
+{
+ struct appctx *appctx = __objt_appctx(si->end);
+
+ if (!stats_fill_info(info, INF_TOTAL_FIELDS))
+ return 0;
+
chunk_reset(&trash);
if (appctx->ctx.stats.flags & STAT_FMT_TYPED)