]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: promex: Dump listeners extra counters if requested
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 29 Jan 2024 15:42:02 +0000 (16:42 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 1 Feb 2024 11:00:54 +0000 (12:00 +0100)
Dump extra counter for the listeners. We loop on stats modules and dumped
all concerned counters. The module name is reported with the "mod" label.

addons/promex/service-prometheus.c

index f7c86835d83576c7e28f990c64c46e2ab1917c71..5cdad6a4afa242d645f40a2396d5f457adb2a91c 100644 (file)
@@ -875,6 +875,78 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
                ctx->li =  LIST_NEXT(&proxies_list->conf.listeners, struct listener *, by_fe);
        }
 
+       /* Skip extra counters */
+       if (!(ctx->flags & PROMEX_FL_EXTRA_COUNTERS))
+               goto end;
+
+       if (!ctx->mod) {
+               /* no restart point, get the first module in the list */
+               ctx->mod = LIST_NEXT(&stats_module_list[STATS_DOMAIN_PROXY], typeof(ctx->mod), list);
+               ctx->mod_field_num = 0;
+       }
+
+       list_for_each_entry_from(ctx->mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
+               void *counters;
+
+               if (!(stats_px_get_cap(ctx->mod->domain_flags) & STATS_PX_CAP_LI)) {
+                       ctx->field_num += ctx->mod->stats_count;
+                       ctx->mod_field_num = 0;
+                       continue;
+               }
+
+               for (;ctx->mod_field_num < ctx->mod->stats_count; ctx->mod_field_num++) {
+                       while (ctx->px) {
+                               struct promex_label labels[PROMEX_MAX_LABELS-1] = {};
+                               struct promex_metric metric;
+
+                               px = ctx->px;
+
+                               labels[0].name  = ist("proxy");
+                               labels[0].value = ist2(px->id, strlen(px->id));
+
+                               /* skip the disabled proxies, global frontend and non-networked ones */
+                               if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
+                                       goto next_px2;
+
+                               li = ctx->li;
+                               list_for_each_entry_from(li, &px->conf.listeners, by_fe) {
+                                       if (!li->counters)
+                                               continue;
+
+                                       labels[1].name  = ist("listener");
+                                       labels[1].value = ist2(li->name, strlen(li->name));
+
+                                       labels[2].name  = ist("mod");
+                                       labels[2].value = ist2(ctx->mod->name, strlen(ctx->mod->name));
+
+                                       counters = EXTRA_COUNTERS_GET(li->extra_counters, ctx->mod);
+                                       if (!ctx->mod->fill_stats(counters, stats + ctx->field_num, &ctx->mod_field_num))
+                                               return -1;
+
+                                       val = stats[ctx->field_num + ctx->mod_field_num];
+                                       metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
+
+                                       if (!promex_dump_metric(appctx, htx, prefix,
+                                                               ist2(ctx->mod->stats[ctx->mod_field_num].name, strlen(ctx->mod->stats[ctx->mod_field_num].name)),
+                                                               ist2(ctx->mod->stats[ctx->mod_field_num].desc, strlen(ctx->mod->stats[ctx->mod_field_num].desc)),
+                                                               &metric, &val, labels, &out, max))
+                                               goto full;
+                               }
+
+                       next_px2:
+                               ctx->px = px->next;
+                               ctx->li = (ctx->px ? LIST_NEXT(&ctx->px->conf.listeners, struct listener *, by_fe) : NULL);
+                       }
+
+                       ctx->flags |= PROMEX_FL_METRIC_HDR;
+                       ctx->px = proxies_list;
+                       ctx->li =  LIST_NEXT(&proxies_list->conf.listeners, struct listener *, by_fe);
+               }
+
+               ctx->field_num += ctx->mod->stats_count;
+               ctx->mod_field_num = 0;
+       }
+
   end:
        if (out.len) {
                if (!htx_add_data_atonce(htx, out))