]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: promex: expose the master and worker IDs as labels
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Sep 2026 11:50:32 +0000 (13:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2026 16:00:51 +0000 (18:00 +0200)
This adds support for emitting the master id when defined (when master
is running) and the worker id. Note that we add a check for the value
being a non-empty string, which remains valid for the few other field
that is always defined (node), so no impact on existing fields.

The output looks like this:

  $ curl -s 0:8181/metrics?metrics=haproxy_process_master_id,haproxy_process_worker_id
  haproxy_process_master_id{master_id="..."} 1
  haproxy_process_worker_id{worker_id="..."} 1

addons/promex/README
addons/promex/service-prometheus.c

index 978052ec8889acbd126ec9870de4906309bfabad..5da7cefc255f6e336f7540d6b89ebc347ef277bc 100644 (file)
@@ -225,6 +225,8 @@ listed below. Metrics from extra counters are not listed.
 | haproxy_process_pool_allocated_bytes           |
 | haproxy_process_pool_used_bytes                |
 | haproxy_process_start_time_seconds             |
+| haproxy_process_master_id                      |
+| haproxy_process_worker_id                      |
 +------------------------------------------------+
 
 * Frontend metrics
index 76ea9a7a7954f22fbd502a7b28d84bd6bdd4c23e..6b302ab3da2e7f64b2b6993983c3963763d89b15 100644 (file)
@@ -460,6 +460,10 @@ static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
 
                switch (ctx->field_num) {
                        case ST_I_INF_NODE:
+                       case ST_I_INF_MASTER_ID:
+                       case ST_I_INF_WORKER_ID:
+                               if (field_format(&val, 0) != FF_STR || !val.u.str)
+                                       continue;
                                labels[lb_idx].name  = name;
                                labels[lb_idx].value = ist(field_str(&val, 0));
                                lb_idx++;