]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: also support a "no-maint" show stat modifier
authorWilly Tarreau <w@1wt.eu>
Fri, 23 Oct 2020 15:28:57 +0000 (17:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 Oct 2020 16:11:24 +0000 (18:11 +0200)
"no-maint" is a bit similar to "up" except that it will only hide
servers that are in maintenance (or disabled in the configuration), and
not those that are enabled but failed a check. One benefit here is to
significantly reduce the output of the "show stat" command when using
large server-templates containing entries that are not yet provisioned.

Note that the prometheus exporter also has such an option which does
the exact same.

doc/management.txt
include/haproxy/stats-t.h
src/http_ana.c
src/stats.c

index 2411405613001f1688873eda2e9994322f008e0a..ca6cfc248a9c0fc922c71af959f392e13975a125 100644 (file)
@@ -2123,7 +2123,7 @@ show fd [<fd>]
   that the output format may evolve over time so this output must not be parsed
   by tools designed to be durable.
 
-show info [typed|json] [desc] [up]
+show info [typed|json] [desc] [up|no-maint]
   Dump info about haproxy status on current process. If "typed" is passed as an
   optional argument, field numbers, names and types are emitted as well so that
   external monitoring products can easily retrieve, possibly aggregate, then
@@ -2138,7 +2138,10 @@ show info [typed|json] [desc] [up]
 
   The "up" modifier will result in listing only servers which reportedly up or
   not checked. Those down, unresolved, or in maintenance will not be listed.
-  This is analogous to the ";up" option on the HTTP stats.
+  This is analogous to the ";up" option on the HTTP stats. Similarly, the
+  "no-maint" modifier will act like the ";no-maint" HTTP modifier and will
+  result in disabled servers not to be listed. The difference is that those
+  which are enabled but down will not be evicted.
 
   When using the typed output format, each line is made of 4 columns delimited
   by colons (':'). The first column is a dot-delimited series of 3 elements. The
index b9e255ca0f944dccddae69a4774c0da8aee42ef9..8b69a0bf83633c4bac0709fd02268024fb86b183 100644 (file)
@@ -40,6 +40,7 @@
 #define STAT_SHLGNDS    0x00000800      /* conf: show legends */
 #define STAT_SHOW_FDESC 0x00001000      /* show the field descriptions when possible */
 #define STAT_SHMODULES  0x00002000      /* conf: show modules */
+#define STAT_HIDE_MAINT 0x00004000     /* hide maint/disabled servers */
 
 #define STAT_BOUND      0x00800000     /* bound statistics to selected proxies/types/services */
 #define STAT_STARTED    0x01000000     /* some output has occurred */
index 1dd43dcc454fbc4e63ce7c070ae75786e8988b7c..f2edc681f9b7791bba766576b93b520a7237b7ac 100644 (file)
@@ -4086,6 +4086,10 @@ static int http_handle_stats(struct stream *s, struct channel *req)
                        appctx->ctx.stats.flags |= STAT_HIDE_DOWN;
                        break;
                }
+               if (memcmp(h, ";no-maint", 3) == 0) {
+                       appctx->ctx.stats.flags |= STAT_HIDE_MAINT;
+                       break;
+               }
        }
 
        if (uri_auth->refresh) {
index f6417b9f83360948c54ff19c2559c66b5e61a6cf..fe027653db8a0862c9fad3a6e2bde2538e46bd0d 100644 (file)
@@ -2565,6 +2565,12 @@ int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
                                        continue;
                        }
 
+                       /* do not report disabled servers */
+                       if (appctx->ctx.stats.flags & STAT_HIDE_MAINT &&
+                           sv->cur_admin & SRV_ADMF_MAINT) {
+                               continue;
+                       }
+
                        svs = sv;
                        while (svs->track)
                                svs = svs->track;
@@ -4310,6 +4316,8 @@ static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx
                        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;
+               else if (strcmp(args[arg], "no-maint") == 0)
+                       appctx->ctx.stats.flags |= STAT_HIDE_MAINT;
                else if (strcmp(args[arg], "up") == 0)
                        appctx->ctx.stats.flags |= STAT_HIDE_DOWN;
                arg++;
@@ -4504,7 +4512,7 @@ REGISTER_CONFIG_POSTPARSER("allocate-stats-dns", allocate_stats_dns_postcheck);
 static struct cli_kw_list cli_kws = {{ },{
        { { "clear", "counters",  NULL }, "clear counters : clear max statistics counters (add 'all' for all counters)", cli_parse_clear_counters, NULL, NULL },
        { { "show", "info",  NULL }, "show info      : report information about the running process [desc|json|typed]*", cli_parse_show_info, cli_io_handler_dump_info, NULL },
-       { { "show", "stat",  NULL }, "show stat      : report counters for each proxy and server [desc|json|typed|up]*", cli_parse_show_stat, cli_io_handler_dump_stat, NULL },
+       { { "show", "stat",  NULL }, "show stat      : report counters for each proxy and server [desc|json|no-maint|typed|up]*", cli_parse_show_stat, cli_io_handler_dump_stat, NULL },
        { { "show", "schema",  "json", NULL }, "show schema json : report schema used for stats", NULL, cli_io_handler_dump_json_schema, NULL },
        {{},}
 }};