]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: add config "stats show modules"
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 5 Oct 2020 09:49:45 +0000 (11:49 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 5 Oct 2020 10:02:14 +0000 (12:02 +0200)
By default, hide the extra statistics on the html page. Define a new
flag STAT_SHMODULES which is activated if the config "stats show
modules" is set.

doc/configuration.txt
include/haproxy/stats-t.h
src/cfgparse-listen.c
src/stats.c

index b01129f8f23d711559709dd9618c4e7e02def6f5..f6eacfbfae24289bcddf0f083dcc1f9d02d80802 100644 (file)
@@ -10036,6 +10036,22 @@ stats show-legends
   See also: "stats enable", "stats uri".
 
 
+stats show-modules
+  Enable display of extra statistics module on the statistics page
+  May be used in sections :   defaults | frontend | listen | backend
+                                 yes   |    yes   |   yes  |   yes
+  Arguments : none
+
+  New columns are added at the end of the line containing the extra statistics
+  values as a tooltip.
+
+  Though this statement alone is enough to enable statistics reporting, it is
+  recommended to set all other settings in order to avoid relying on default
+  unobvious parameters. Default behavior is not to show this information.
+
+  See also: "stats enable", "stats uri".
+
+
 stats show-node [ <name> ]
   Enable reporting of a host name on the statistics page.
   May be used in sections :   defaults | frontend | listen | backend
index 96dcf18d8975f8cec933f21916124f15ebf15aa6..d1486512470974f971f576bd9f45cef1f941e3fb 100644 (file)
@@ -39,6 +39,7 @@
 #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_SHMODULES  0x00002000      /* conf: show modules */
 
 #define STAT_BOUND      0x00800000     /* bound statistics to selected proxies/types/services */
 #define STAT_STARTED    0x01000000     /* some output has occurred */
index b8f379524777b458ba544c459f8484cc69613e41..c2db644c8ed60f6ae199ad01139e367a04da1a7f 100644 (file)
@@ -1923,6 +1923,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                err_code |= ERR_ALERT | ERR_ABORT;
                                goto out;
                        }
+               } else if (!strcmp(args[1], "show-modules")) {
+                       if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
+                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
+                               err_code |= ERR_ALERT | ERR_ABORT;
+                               goto out;
+                       }
                } else if (!strcmp(args[1], "show-node")) {
 
                        if (*args[2]) {
index ae2f58d2b73ce25d37cda247308c7a59ce65d7a8..f84488a1771ec4599863bf39bdfcd70d9d467357 100644 (file)
@@ -764,7 +764,9 @@ err:
 
 /* Dump all fields from <stats> into <out> using the HTML format. A column is
  * reserved for the checkbox is STAT_ADMIN is set in <flags>. Some extra info
- * are provided if STAT_SHLGNDS is present in <flags>.
+ * are provided if STAT_SHLGNDS is present in <flags>. The statistics from
+ * extra modules are displayed at the end of the lines if STAT_SHMODULES is
+ * present in <flags>.
  */
 static int stats_dump_fields_html(struct buffer *out,
                                  const struct field *stats,
@@ -922,23 +924,25 @@ static int stats_dump_fields_html(struct buffer *out,
                              U2H(stats[ST_F_EREQ].u.u64),
                              field_str(stats, ST_F_STATUS));
 
-               list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-                       chunk_appendf(out,
-                                     "<td><u>%s<div class=tips><table class=det>",
-                                     mod->name);
-                       if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE) {
-                               for (j = 0; j < mod->stats_count; ++j) {
-                                       chunk_appendf(out,
-                                                     "<tr><th>%s</th><td>%s</td></tr>",
-                                                     mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
-                                       ++i;
+               if (flags & STAT_SHMODULES) {
+                       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+                               chunk_appendf(out,
+                                             "<td><u>%s<div class=tips><table class=det>",
+                                             mod->name);
+                               if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE) {
+                                       for (j = 0; j < mod->stats_count; ++j) {
+                                               chunk_appendf(out,
+                                                             "<tr><th>%s</th><td>%s</td></tr>",
+                                                             mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
+                                               ++i;
+                                       }
+                               } else {
+                                       i += mod->stats_count;
                                }
-                       } else {
-                               i += mod->stats_count;
-                       }
 
-                       chunk_appendf(out,
-                                     "</table></div></u></td>");
+                               chunk_appendf(out,
+                                             "</table></div></u></td>");
+                       }
                }
 
                chunk_appendf(out, "</tr>");
@@ -1004,23 +1008,25 @@ static int stats_dump_fields_html(struct buffer *out,
                              U2H(stats[ST_F_EREQ].u.u64),
                              field_str(stats, ST_F_STATUS));
 
-               list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-                       chunk_appendf(out,
-                                     "<td><u>%s<div class=tips><table class=det>",
-                                     mod->name);
-                       if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI) {
-                               for (j = 0; j < mod->stats_count; ++j) {
-                                       chunk_appendf(out,
-                                                     "<tr><th>%s</th><td>%s</td></tr>",
-                                                     mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
-                                       ++i;
+               if (flags & STAT_SHMODULES) {
+                       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+                               chunk_appendf(out,
+                                             "<td><u>%s<div class=tips><table class=det>",
+                                             mod->name);
+                               if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI) {
+                                       for (j = 0; j < mod->stats_count; ++j) {
+                                               chunk_appendf(out,
+                                                             "<tr><th>%s</th><td>%s</td></tr>",
+                                                             mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
+                                               ++i;
+                                       }
+                               } else {
+                                       i += mod->stats_count;
                                }
-                       } else {
-                               i += mod->stats_count;
-                       }
 
-                       chunk_appendf(out,
-                                     "</table></div></u></td>");
+                               chunk_appendf(out,
+                                             "</table></div></u></td>");
+                       }
                }
 
                chunk_appendf(out, "</tr>");
@@ -1340,23 +1346,25 @@ static int stats_dump_fields_html(struct buffer *out,
                else
                        chunk_appendf(out, "<td class=ac>-</td>");
 
-               list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-                       chunk_appendf(out,
-                                     "<td><u>%s<div class=tips><table class=det>",
-                                     mod->name);
-                       if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV) {
-                               for (j = 0; j < mod->stats_count; ++j) {
-                                       chunk_appendf(out,
-                                                     "<tr><th>%s</th><td>%s</td></tr>",
-                                                     mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
-                                       ++i;
+               if (flags & STAT_SHMODULES) {
+                       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+                               chunk_appendf(out,
+                                             "<td><u>%s<div class=tips><table class=det>",
+                                             mod->name);
+                               if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV) {
+                                       for (j = 0; j < mod->stats_count; ++j) {
+                                               chunk_appendf(out,
+                                                             "<tr><th>%s</th><td>%s</td></tr>",
+                                                             mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
+                                               ++i;
+                                       }
+                               } else {
+                                       i += mod->stats_count;
                                }
-                       } else {
-                               i += mod->stats_count;
-                       }
 
-                       chunk_appendf(out,
-                                     "</table></div></u></td>");
+                               chunk_appendf(out,
+                                             "</table></div></u></td>");
+                       }
                }
 
                chunk_appendf(out, "</tr>\n");
@@ -1529,23 +1537,26 @@ static int stats_dump_fields_html(struct buffer *out,
                              stats[ST_F_CHKDOWN].u.u32,
                              stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : "&nbsp;");
 
-               list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-                       chunk_appendf(out,
-                                     "<td><u>%s<div class=tips><table class=det>",
-                                     mod->name);
-                       if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE) {
-                               for (j = 0; j < mod->stats_count; ++j) {
-                                       chunk_appendf(out,
-                                                     "<tr><th>%s</th><td>%s</td></tr>",
-                                                     mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
-                                       ++i;
+               if (flags & STAT_SHMODULES) {
+                       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+                               chunk_appendf(out,
+                                             "<td><u>%s<div class=tips><table class=det>",
+                                             mod->name);
+                               if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE) {
+                                       for (j = 0; j < mod->stats_count; ++j) {
+                                               chunk_appendf(out,
+                                                             "<tr><th>%s</th><td>%s</td></tr>",
+                                                             mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i]));
+                                               ++i;
+                                       }
+                               } else {
+                                       i += mod->stats_count;
                                }
-                       } else {
-                               i += mod->stats_count;
+                               chunk_appendf(out,
+                                             "</table></div></u></td>");
                        }
-                       chunk_appendf(out,
-                                     "</table></div></u></td>");
                }
+
                chunk_appendf(out, "</tr>");
        }
 
@@ -2316,19 +2327,24 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
                        chunk_appendf(&trash, "<th rowspan=2></th>");
        }
 
-       // calculate the count of module for colspan attribute
-       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               ++stats_module_len;
-       }
-
        chunk_appendf(&trash,
                      "<th rowspan=2></th>"
                      "<th colspan=3>Queue</th>"
                      "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
                      "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
                      "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
-                     "<th colspan=9>Server</th>"
-                     "<th colspan=%d>Extra modules</th>"
+                     "<th colspan=9>Server</th>");
+
+       if (appctx->ctx.stats.flags & STAT_SHMODULES) {
+               // calculate the count of module for colspan attribute
+               list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+                       ++stats_module_len;
+               }
+               chunk_appendf(&trash, "<th colspan=%d>Extra modules</th>",
+                             stats_module_len);
+       }
+
+       chunk_appendf(&trash,
                      "</tr>\n"
                      "<tr class=\"titre\">"
                      "<th>Cur</th><th>Max</th><th>Limit</th>"
@@ -2338,10 +2354,12 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
                      "<th>Resp</th><th>Retr</th><th>Redis</th>"
                      "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
                      "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
-                     "<th>Thrtle</th>\n", stats_module_len);
+                     "<th>Thrtle</th>\n");
 
-       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               chunk_appendf(&trash, "<th>%s</th>", mod->name);
+       if (appctx->ctx.stats.flags & STAT_SHMODULES) {
+               list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+                       chunk_appendf(&trash, "<th>%s</th>", mod->name);
+               }
        }
 
        chunk_appendf(&trash, "</tr>");