]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: support the "desc" output format modifier for info and stat
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Oct 2019 09:43:59 +0000 (11:43 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Oct 2019 09:30:07 +0000 (11:30 +0200)
Now "show info" and "show stat" can parse "desc" as an output format
modifier that will be passed down the chain to add some descriptions
to the fields depending on the format in use. For now it is not
exploited.

include/types/stats.h
src/stats.c

index d078b676d89e731918222fad2a3c9e9c7679389c..8817746b36bae96cf3aa3cf05e20399eb696436d 100644 (file)
@@ -34,6 +34,7 @@
 #define STAT_SHNODE     0x00000200      /* conf: show node name */
 #define STAT_SHDESC     0x00000400      /* conf: show description */
 #define STAT_SHLGNDS    0x00000800      /* conf: show legends */
+#define STAT_SHOW_FDESC 0x00001000      /* show the field descriptions when possible */
 
 #define STAT_BOUND      0x00800000     /* bound statistics to selected proxies/types/services */
 #define STAT_STARTED    0x01000000     /* some output has occurred */
index b14256710f5305746d47386c864ab312e82ea8dc..4c51a868bdd6b32d7ebf0f3854afd59ea0c861d4 100644 (file)
@@ -3782,20 +3782,29 @@ static int cli_parse_clear_counters(char **args, char *payload, struct appctx *a
 
 static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private)
 {
+       int arg = 2;
+
        appctx->ctx.stats.scope_str = 0;
        appctx->ctx.stats.scope_len = 0;
        appctx->ctx.stats.flags = 0;
 
-       if (strcmp(args[2], "typed") == 0)
-               appctx->ctx.stats.flags |= STAT_FMT_TYPED;
-       else if (strcmp(args[2], "json") == 0)
-               appctx->ctx.stats.flags |= STAT_FMT_JSON;
+       while (*args[arg]) {
+               if (strcmp(args[arg], "typed") == 0)
+                       appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED;
+               else if (strcmp(args[arg], "json") == 0)
+                       appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON;
+               else if (strcmp(args[arg], "desc") == 0)
+                       appctx->ctx.stats.flags |= STAT_SHOW_FDESC;
+               arg++;
+       }
        return 0;
 }
 
 
 static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private)
 {
+       int arg = 2;
+
        appctx->ctx.stats.scope_str = 0;
        appctx->ctx.stats.scope_len = 0;
        appctx->ctx.stats.flags = STAT_SHNODE | STAT_SHDESC;
@@ -3803,30 +3812,33 @@ static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx
        if ((strm_li(si_strm(appctx->owner))->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER)
                appctx->ctx.stats.flags |= STAT_SHLGNDS;
 
-       if (*args[2] && *args[3] && *args[4]) {
+       if (*args[arg] && *args[arg+1] && *args[arg+2]) {
                struct proxy *px;
 
-               px = proxy_find_by_name(args[2], 0, 0);
+               px = proxy_find_by_name(args[arg], 0, 0);
                if (px)
                        appctx->ctx.stats.iid = px->uuid;
                else
-                       appctx->ctx.stats.iid = atoi(args[2]);
+                       appctx->ctx.stats.iid = atoi(args[arg]);
 
                if (!appctx->ctx.stats.iid)
                        return cli_err(appctx, "No such proxy.\n");
 
                appctx->ctx.stats.flags |= STAT_BOUND;
-               appctx->ctx.stats.type = atoi(args[3]);
-               appctx->ctx.stats.sid = atoi(args[4]);
-               if (strcmp(args[5], "typed") == 0)
-                       appctx->ctx.stats.flags |= STAT_FMT_TYPED;
-               else if (strcmp(args[5], "json") == 0)
-                       appctx->ctx.stats.flags |= STAT_FMT_JSON;
-       }
-       else if (strcmp(args[2], "typed") == 0)
-               appctx->ctx.stats.flags |= STAT_FMT_TYPED;
-       else if (strcmp(args[2], "json") == 0)
-               appctx->ctx.stats.flags |= STAT_FMT_JSON;
+               appctx->ctx.stats.type = atoi(args[arg+1]);
+               appctx->ctx.stats.sid = atoi(args[arg+2]);
+               arg += 3;
+       }
+
+       while (*args[arg]) {
+               if (strcmp(args[arg], "typed") == 0)
+                       appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED;
+               else if (strcmp(args[arg], "json") == 0)
+                       appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON;
+               else if (strcmp(args[arg], "desc") == 0)
+                       appctx->ctx.stats.flags |= STAT_SHOW_FDESC;
+               arg++;
+       }
 
        return 0;
 }