]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: stats: report the process IDs on the HTML page with "stats show-node"
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Sep 2026 14:21:18 +0000 (16:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2026 16:00:51 +0000 (18:00 +0200)
This adds the worker-id and (optionally) master-id on the output next to
the node when "stats show-node" is present, since these generally go
together. No escaping is needed since guid_is_valid_fmt() only allows
alphanumerical values and '.', ':', '-' and '_'.

doc/configuration.txt
src/stats-html.c

index 3b44d7592218e5cdaf09202d1df027e369eb68bd..768521189981c1fbcec09a6424fbaa0644df1574 100644 (file)
@@ -3848,10 +3848,10 @@ worker-id <id>
       worker-id "pop7-node1-inst3-${HAPROXY_WORKER_ID}"
 
   The identifier is exported as the HAPROXY_WORKER_ID environment variable (see
-  section 2.3), is returned by the "worker_id" sample fetch function and on the
-  output of the "show info" CLI command. See also the "HAPROXY_MASTER_ID"
-  environment variable in section 2.3, and the "worker_id" sample fetch
-  function.
+  section 2.3), is returned by the "worker_id" sample fetch function, appears
+  on the output of the "show info" CLI command and on the HTML stats page when
+  "stats show-node" is enabled. See also the "HAPROXY_MASTER_ID" environment
+  variable in section 2.3, and the "worker_id" sample fetch function.
 
 wurfl-cache-size <size>
   Sets the WURFL Useragent cache size. For faster lookups, already processed user
@@ -13566,6 +13566,9 @@ stats show-node [ <name> ]
   This statement is useful for users that offer shared services to their
   customers, where node or description might be different on a stats page
   provided for each customer. Default behavior is not to show host name.
+  When enabled, the identifiers of the master process (when present) and the
+  worker process are also shown. This can be useful to more easily detect
+  reloads for example. See "worker-id" in the global section.
 
   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
@@ -13579,8 +13582,8 @@ stats show-node [ <name> ]
         stats uri       /admin?stats
         stats refresh   5s
 
-  See also: "show-desc", "stats enable", "stats uri", and "node" in global
-            section.
+  See also: "show-desc", "stats enable", "stats uri", "worker-id" and "node" in
+            global section.
 
 stats show-version
   Enable statistics and show HAProxy version reporting
index ae256fb02dc5c64a5cd593b433a9a02abe117ef7..2eed3ef437e9ef2a019733aa6d82d715b56ba051 100644 (file)
@@ -1,5 +1,6 @@
 #include <haproxy/stats-html.h>
 
+#include <stdio.h>
 #include <string.h>
 
 #include <import/ist.h>
@@ -232,6 +233,8 @@ void stats_dump_html_info(struct stconn *sc)
        const char *scope_ptr = stats_scope_ptr(appctx);
        struct uri_auth *uri;
        unsigned long long bps;
+       /* large enough for two forced GUID_MAX_LEN identifiers and the tags */
+       char proc_ids[384] = "";
        int thr;
 
        BUG_ON(!ctx->http_px);
@@ -250,6 +253,21 @@ void stats_dump_html_info(struct stconn *sc)
         */
        bps = bps * 8 * 1538 / 1448;
 
+       /* The process' unique identifiers are reported along with the node
+        * name, as they're complementary. The master comes first so that the
+        * creation chain reads naturally, and it is absent when not running in
+        * master-worker mode. These identifiers are only made of characters
+        * which are valid in a GUID so they never need to be escaped.
+        */
+       if ((ctx->flags & STAT_F_SHNODE) && global.worker_id) {
+               snprintf(proc_ids, sizeof(proc_ids),
+                        "%s%s%s<b>worker-id = </b> %s<br>\n",
+                        global.master_id ? "<b>master-id = </b> " : "",
+                        global.master_id ? global.master_id : "",
+                        global.master_id ? "; " : "",
+                        global.worker_id);
+       }
+
        /* WARNING! this has to fit the first packet too.
         * We are around 3.5 kB, add adding entries will
         * become tricky if we want to support 4kB buffers !
@@ -262,6 +280,7 @@ void stats_dump_html_info(struct stconn *sc)
                      "<h3>&gt; General process information</h3>\n"
                      "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
                      "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n"
+                     "%s"
                      "<b>uptime = </b> %dd %dh%02dm%02ds; warnings = %u<br>\n"
                      "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
                      "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>reached = </b> %llu; <b>maxpipes = </b> %d<br>\n"
@@ -296,6 +315,7 @@ void stats_dump_html_info(struct stconn *sc)
                      (ctx->flags & STAT_F_SHDESC) ? ": " : "",
                      (ctx->flags & STAT_F_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
                      pid, 1, 1, global.nbthread,
+                     proc_ids,
                      up / 86400, (up % 86400) / 3600,
                      (up % 3600) / 60, (up % 60),
                      HA_ATOMIC_LOAD(&tot_warnings),