]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dumpstats: split stats_dump_be_stats() in two parts
authorThierry Fournier <tfournier@arpalert.org>
Fri, 25 Mar 2016 07:21:51 +0000 (08:21 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2016 15:26:19 +0000 (17:26 +0200)
This patch splits the function stats_dump_be_stats() in two parts. The
part is called stats_fill_be_stats(), 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 a162e69f6e20d2e44ff18841a672d7baaf7e9bea..c446722f657344671f28142bc185e4f944cc3dd2 100644 (file)
@@ -397,6 +397,7 @@ int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
                         struct field *stats, int len);
 int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
                         struct field *stats, int len);
+int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len);
 
 extern struct applet http_stats_applet;
 
index 10b9cd31d20f5cb46aba72f3518279a70fb1fe0b..447e6f0cc37e7e6de51c374d3a82d20fb0b23ada 100644 (file)
@@ -4338,21 +4338,18 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
        return stats_dump_one_line(stats, flags, px, appctx);
 }
 
-/* Dumps a line for backend <px> to the trash for and uses the state from stream
- * interface <si> and stats flags <flags>. The caller is responsible for clearing
- * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
+/* Fill <stats> with the backend statistics. <stats> is
+ * preallocated array of length <len>. The length of the array
+ * must be at least ST_F_TOTAL_FIELDS. If this length is less
+ * then this value, the function returns 0, otherwise, it
+ * returns 1. <flags> can take the value ST_SHLGNDS.
  */
-static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
+int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
 {
-       struct appctx *appctx = __objt_appctx(si->end);
-
-       if (!(px->cap & PR_CAP_BE))
-               return 0;
-
-       if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
+       if (len < ST_F_TOTAL_FIELDS)
                return 0;
 
-       memset(&stats, 0, sizeof(stats));
+       memset(stats, 0, sizeof(*stats) * len);
 
        stats[ST_F_PXNAME]   = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
        stats[ST_F_SVNAME]   = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND");
@@ -4421,6 +4418,26 @@ 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));
 
+       return 1;
+}
+
+/* Dumps a line for backend <px> to the trash for and uses the state from stream
+ * interface <si> and stats flags <flags>. The caller is responsible for clearing
+ * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
+ */
+static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
+{
+       struct appctx *appctx = __objt_appctx(si->end);
+
+       if (!(px->cap & PR_CAP_BE))
+               return 0;
+
+       if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
+               return 0;
+
+       if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS))
+               return 0;
+
        return stats_dump_one_line(stats, flags, px, appctx);
 }