return 1;
}
-/* Dump the time series header lines for <metric>. It is its #HELP and #TYPE
+/* Dump the time series header lines for the metric <name>. It is its #HELP and #TYPE
* strings. It returns 1 on success. Otherwise, if <out> length exceeds <max>,
* it returns 0.
*/
-static int promex_dump_ts_header(struct appctx *appctx, const struct promex_metric *metric,
- const struct ist name, const struct ist d,
+static int promex_dump_ts_header(const struct ist name, const struct ist desc, enum promex_mt_type type,
struct ist *out, size_t max)
{
- struct promex_ctx *ctx = appctx->svcctx;
- struct ist type;
- struct ist desc;
+ struct ist t;
- switch (metric->type) {
+ switch (type) {
case PROMEX_MT_COUNTER:
- type = ist("counter");
+ t = ist("counter");
break;
default:
- type = ist("gauge");
+ t = ist("gauge");
}
if (istcat(out, ist("# HELP "), max) == -1 ||
istcat(out, ist(" "), max) == -1)
goto full;
- if (isttest(d))
- desc = d;
- else if (metric->flags & PROMEX_FL_INFO_METRIC)
- desc = ist(info_fields[ctx->field_num].desc);
- else if (!isttest(promex_st_metric_desc[ctx->field_num]))
- desc = ist(stat_fields[ctx->field_num].desc);
+ if (istcat(out, ist("# HELP "), max) == -1 ||
+ istcat(out, name, max) == -1 ||
+ istcat(out, ist(" "), max) == -1 ||
+ istcat(out, desc, max) == -1)
+ goto full;
- if (istcat(out, desc, max) == -1 ||
- istcat(out, ist("\n# TYPE "), max) == -1 ||
+ if (istcat(out, ist("\n# TYPE "), max) == -1 ||
istcat(out, name, max) == -1 ||
istcat(out, ist(" "), max) == -1 ||
- istcat(out, type, max) == -1 ||
+ istcat(out, t, max) == -1 ||
istcat(out, ist("\n"), max) == -1)
goto full;
return 0;
}
-/* Dump the time series for <metric>. It starts by the metric name followed by
+/* Dump the time series for the metric <name>. It starts by the metric name followed by
* its labels (proxy name, server name...) between braces and finally its
* value. If not already done, the header lines are dumped first. It returns 1
* on success. Otherwise if <out> length exceeds <max>, it returns 0.
*/
static int promex_dump_ts(struct appctx *appctx, struct ist prefix,
- const struct ist n, const struct ist desc, const struct promex_metric *metric,
+ const struct ist name, const struct ist desc, enum promex_mt_type type,
struct field *val, struct promex_label *labels, struct ist *out, size_t max)
{
- struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
+ struct ist n = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
struct promex_ctx *ctx = appctx->svcctx;
size_t len = out->len;
if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
return 0;
+
/* Fill the metric name */
- istcat(&name, prefix, PROMEX_MAX_NAME_LEN);
- istcat(&name, (isttest(n) ? n : metric->n), PROMEX_MAX_NAME_LEN);
+ istcat(&n, prefix, PROMEX_MAX_NAME_LEN);
+ istcat(&n, name, PROMEX_MAX_NAME_LEN);
if ((ctx->flags & PROMEX_FL_METRIC_HDR) &&
- !promex_dump_ts_header(appctx, metric, name, desc, out, max))
+ !promex_dump_ts_header(n, desc, type, out, max))
goto full;
- if (istcat(out, name, max) == -1)
+ if (istcat(out, n, max) == -1)
goto full;
if (isttest(labels[0].name)) {
struct promex_ctx *ctx = appctx->svcctx;
struct field val;
struct channel *chn = sc_ic(appctx_sc(appctx));
- struct ist out = ist2(trash.area, 0);
+ struct ist name, desc, out = ist2(trash.area, 0);
size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
int ret = 1;
if (!(promex_global_metrics[ctx->field_num].flags & ctx->flags))
continue;
+ name = promex_global_metrics[ctx->field_num].n;
+ desc = ist(info_fields[ctx->field_num].desc);
+
switch (ctx->field_num) {
case INF_BUILD_INFO:
labels[0].name = ist("version");
val = info[ctx->field_num];
}
- if (!promex_dump_ts(appctx, prefix, IST_NULL, IST_NULL,
- &promex_global_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_global_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
struct stats_module *mod = ctx->p[1];
struct field val;
struct channel *chn = sc_ic(appctx_sc(appctx));
- struct ist out = ist2(trash.area, 0);
+ struct ist name, desc, out = ist2(trash.area, 0);
size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
struct field *stats = stat_l[STATS_DOMAIN_PROXY];
int ret = 1;
if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags))
continue;
+ name = promex_st_front_metrics_names[ctx->field_num];
+ desc = promex_st_metric_desc[ctx->field_num];
+
+ if (!isttest(name))
+ name = promex_st_metrics[ctx->field_num].n;
+ if (!isttest(desc))
+ desc = ist(stat_fields[ctx->field_num].desc);
+
if (!px)
px = proxies_list;
labels[1].value = promex_front_st[ctx->obj_state];
val = mkf_u32(FO_STATUS, state == ctx->obj_state);
- if (!promex_dump_ts(appctx, prefix,
- promex_st_front_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
val = stats[ctx->field_num];
}
- if (!promex_dump_ts(appctx, prefix,
- promex_st_front_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
next_px:
}
for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) {
+ name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name));
+ desc = ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc));
+
if (!px)
px = proxies_list;
val = stats[ctx->field_num + ctx->mod_field_num];
metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
- if (!promex_dump_ts(appctx, prefix,
- ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
- ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
- &metric, &val, labels, &out, max))
+ if (!promex_dump_ts(appctx, prefix, name, desc, metric.type,
+ &val, labels, &out, max))
goto full;
next_px2:
struct stats_module *mod = ctx->p[2];
struct field val;
struct channel *chn = sc_ic(appctx_sc(appctx));
- struct ist out = ist2(trash.area, 0);
+ struct ist name, desc, out = ist2(trash.area, 0);
size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
struct field *stats = stat_l[STATS_DOMAIN_PROXY];
int ret = 1;
if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags))
continue;
+ name = promex_st_li_metrics_names[ctx->field_num];
+ desc = promex_st_metric_desc[ctx->field_num];
+
+ if (!isttest(name))
+ name = promex_st_metrics[ctx->field_num].n;
+ if (!isttest(desc))
+ desc = ist(stat_fields[ctx->field_num].desc);
+
if (!px)
px = proxies_list;
val = mkf_u32(FO_STATUS, status == ctx->obj_state);
labels[2].name = ist("state");
labels[2].value = ist(li_status_st[ctx->obj_state]);
- if (!promex_dump_ts(appctx, prefix,
- promex_st_li_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
val = stats[ctx->field_num];
}
- if (!promex_dump_ts(appctx, prefix,
- promex_st_li_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
}
for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) {
+ name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name));
+ desc = ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc));
+
if (!px)
px = proxies_list;
val = stats[ctx->field_num + ctx->mod_field_num];
metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
- if (!promex_dump_ts(appctx, prefix,
- ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
- ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
- &metric, &val, labels, &out, max))
+ if (!promex_dump_ts(appctx, prefix, name, desc, metric.type,
+ &val, labels, &out, max))
goto full;
}
li = NULL;
struct server *sv;
struct field val;
struct channel *chn = sc_ic(appctx_sc(appctx));
- struct ist out = ist2(trash.area, 0);
+ struct ist name, desc, out = ist2(trash.area, 0);
size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
struct field *stats = stat_l[STATS_DOMAIN_PROXY];
int ret = 1;
if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags))
continue;
+ name = promex_st_back_metrics_names[ctx->field_num];
+ desc = promex_st_metric_desc[ctx->field_num];
+
+ if (!isttest(name))
+ name = promex_st_metrics[ctx->field_num].n;
+ if (!isttest(desc))
+ desc = ist(stat_fields[ctx->field_num].desc);
+
if (!px)
px = proxies_list;
val = mkf_u32(FN_GAUGE, srv_state_count[ctx->obj_state]);
labels[1].name = ist("state");
labels[1].value = promex_srv_st[ctx->obj_state];
- if (!promex_dump_ts(appctx, prefix,
- promex_st_back_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
check_state = get_check_status_info(ctx->obj_state);
labels[1].name = ist("state");
labels[1].value = ist(check_state);
- if (!promex_dump_ts(appctx, prefix,
- promex_st_back_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
labels[1].name = ist("state");
labels[1].value = promex_back_st[ctx->obj_state];
val = mkf_u32(FO_STATUS, bkd_state == ctx->obj_state);
- if (!promex_dump_ts(appctx, prefix,
- promex_st_back_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
val = stats[ctx->field_num];
}
- if (!promex_dump_ts(appctx, prefix,
- promex_st_back_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
next_px:
}
for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) {
+ name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name));
+ desc = ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc));
+
if (!px)
px = proxies_list;
val = stats[ctx->field_num + ctx->mod_field_num];
metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
- if (!promex_dump_ts(appctx, prefix,
- ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
- ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
- &metric, &val, labels, &out, max))
+ if (!promex_dump_ts(appctx, prefix, name, desc, metric.type,
+ &val, labels, &out, max))
goto full;
next_px2:
struct stats_module *mod = ctx->p[2];
struct field val;
struct channel *chn = sc_ic(appctx_sc(appctx));
- struct ist out = ist2(trash.area, 0);
+ struct ist name, desc, out = ist2(trash.area, 0);
size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
struct field *stats = stat_l[STATS_DOMAIN_PROXY];
int ret = 1;
if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags))
continue;
+ name = promex_st_srv_metrics_names[ctx->field_num];
+ desc = promex_st_metric_desc[ctx->field_num];
+
+ if (!isttest(name))
+ name = promex_st_metrics[ctx->field_num].n;
+ if (!isttest(desc))
+ desc = ist(stat_fields[ctx->field_num].desc);
+
if (!px)
px = proxies_list;
val = mkf_u32(FO_STATUS, state == ctx->obj_state);
labels[2].name = ist("state");
labels[2].value = promex_srv_st[ctx->obj_state];
- if (!promex_dump_ts(appctx, prefix,
- promex_st_srv_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
check_state = get_check_status_info(ctx->obj_state);
labels[2].name = ist("state");
labels[2].value = ist(check_state);
- if (!promex_dump_ts(appctx, prefix,
- promex_st_srv_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
}
val = stats[ctx->field_num];
}
- if (!promex_dump_ts(appctx, prefix,
- promex_st_srv_metrics_names[ctx->field_num],
- promex_st_metric_desc[ctx->field_num],
- &promex_st_metrics[ctx->field_num],
+ if (!promex_dump_ts(appctx, prefix, name, desc,
+ promex_st_metrics[ctx->field_num].type,
&val, labels, &out, max))
goto full;
next_sv:
}
for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) {
+ name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name));
+ desc = ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc));
+
if (!px)
px = proxies_list;
val = stats[ctx->field_num + ctx->mod_field_num];
metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
- if (!promex_dump_ts(appctx, prefix,
- ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)),
- ist2(mod->stats[ctx->mod_field_num].desc, strlen(mod->stats[ctx->mod_field_num].desc)),
- &metric, &val, labels, &out, max))
+ if (!promex_dump_ts(appctx, prefix, name, desc, metric.type,
+ &val, labels, &out, max))
goto full;
next_sv2:
if (ret < 0)
goto error;
- if (!promex_dump_ts(appctx, prefix, IST_NULL, desc, &metric,
+ if (!promex_dump_ts(appctx, prefix, metric.n, desc, metric.type,
&val, labels, out, max))
goto full;