]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dumpstats: split stats_dump_info_to_buffer() in two parts
authorThierry Fournier <tfournier@arpalert.org>
Fri, 25 Mar 2016 07:19:23 +0000 (08:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2016 15:21:37 +0000 (17:21 +0200)
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.

include/proto/dumpstats.h
src/dumpstats.c

index 9db2eece080566f9bb32dde083e0b28c378649f0..ac0c0b557aec959033157afbfbfafc53a8111ecd 100644 (file)
@@ -391,6 +391,8 @@ static inline struct field mkf_str(uint32_t type, const char *value)
 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);
index 833dd9f8c0bc9c31a40ede6d5fac47f6edfbe5a3..0474eab9ba7a563af6d88c8a4d01dcbcfb720f63 100644 (file)
@@ -2948,15 +2948,15 @@ static int stats_dump_typed_info_fields(struct chunk *out, const struct field *i
        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 @@ static int stats_dump_info_to_buffer(struct stream_interface *si)
        }
 #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 @@ static int stats_dump_info_to_buffer(struct stream_interface *si)
        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)