From: Willy Tarreau Date: Tue, 15 Sep 2026 14:21:18 +0000 (+0200) Subject: MINOR: stats: report the process IDs on the HTML page with "stats show-node" X-Git-Tag: v3.5-dev7~5 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=04ab50253cd884831199036290be076edeaf78f2;p=haproxy.git MINOR: stats: report the process IDs on the HTML page with "stats show-node" 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 '_'. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 3b44d7592..768521189 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3848,10 +3848,10 @@ worker-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 Sets the WURFL Useragent cache size. For faster lookups, already processed user @@ -13566,6 +13566,9 @@ stats show-node [ ] 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 [ ] 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 diff --git a/src/stats-html.c b/src/stats-html.c index ae256fb02..2eed3ef43 100644 --- a/src/stats-html.c +++ b/src/stats-html.c @@ -1,5 +1,6 @@ #include +#include #include #include @@ -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%sworker-id = %s
\n", + global.master_id ? "master-id = " : "", + 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) "

> General process information

\n" "
\n" "

pid = %d (process #%d, nbproc = %d, nbthread = %d)
\n" + "%s" "uptime = %dd %dh%02dm%02ds; warnings = %u
\n" "system limits: memmax = %s%s; ulimit-n = %d
\n" "maxsock = %d; maxconn = %d; reached = %llu; maxpipes = %d
\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),