[PATCH 1/2] [PATCH] BUG/MINOR: promex: rename haproxy_backend_agg_server_check_status
haproxy_backend_agg_server_check_status currently aggregates haproxy_server_status instead of haproxy_server_check_status. Rename the metric to haproxy_backend_agg_server_status to clarify what it really does. --- addons/promex/service-prometheus.c | 4 ++-- include/haproxy/stats-t.h | 2 +- src/stats.c| 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index d27aefaaa..c24f0895c 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -301,7 +301,7 @@ const struct promex_metric promex_st_metrics[ST_F_TOTAL_FIELDS] = { [ST_F_USED_CONN_CUR]= { .n = IST("used_connections_current"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_SRV_METRIC) }, [ST_F_NEED_CONN_EST]= { .n = IST("need_connections_current"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_SRV_METRIC) }, [ST_F_UWEIGHT] = { .n = IST("uweight"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, - [ST_F_AGG_SRV_CHECK_STATUS] = { .n = IST("agg_server_check_status"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_BACK_METRIC ) }, + [ST_F_AGG_SRV_STATUS ] = { .n = IST("agg_server_status"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_BACK_METRIC ) }, }; /* Description of overridden stats fields */ @@ -833,7 +833,7 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) return -1; switch (ctx->field_num) { - case ST_F_AGG_SRV_CHECK_STATUS: + case ST_F_AGG_SRV_STATUS : if (!px->srv) goto next_px; sv = px->srv; diff --git a/include/haproxy/stats-t.h b/include/haproxy/stats-t.h index efa0ac383..babea31e1 100644 --- a/include/haproxy/stats-t.h +++ b/include/haproxy/stats-t.h @@ -455,7 +455,7 @@ enum stat_field { ST_F_USED_CONN_CUR, ST_F_NEED_CONN_EST, ST_F_UWEIGHT, - ST_F_AGG_SRV_CHECK_STATUS, + ST_F_AGG_SRV_STATUS , /* must always be the last one */ ST_F_TOTAL_FIELDS diff --git a/src/stats.c b/src/stats.c index 97e7fd865..dd3044b58 100644 --- a/src/stats.c +++ b/src/stats.c @@ -259,7 +259,7 @@ const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = { [ST_F_USED_CONN_CUR] = { .name = "used_conn_cur", .desc = "Current number of connections in use"}, [ST_F_NEED_CONN_EST] = { .name = "need_conn_est", .desc = "Estimated needed number of connections"}, [ST_F_UWEIGHT] = { .name = "uweight", .desc = "Server's user weight, or sum of active servers' user weights for a backend" }, - [ST_F_AGG_SRV_CHECK_STATUS] = { .name = "agg_server_check_status", .desc = "Backend's aggregated gauge of servers' state check status" }, + [ST_F_AGG_SRV_STATUS ] = { .name = "agg_server_status", .desc = "Backend's aggregated gauge of servers' status" }, }; /* one line of info */ @@ -2673,7 +2673,7 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le chunk_appendf(out, " (%d/%d)", nbup, nbsrv); metric = mkf_str(FO_STATUS, fld); break; - case ST_F_AGG_SRV_CHECK_STATUS: + case ST_F_AGG_SRV_STATUS : metric = mkf_u32(FN_GAUGE, 0); break; case ST_F_WEIGHT: -- 2.25.1
[PATCH 2/2] [PATCH] MINOR: promex: reintroduce haproxy_backend_agg_server_check_status
This patch reintroduces haproxy_backend_agg_server_check_status metric as in 42d7c402d but with the right data source. --- addons/promex/service-prometheus.c | 26 ++ include/haproxy/stats-t.h | 1 + src/stats.c| 4 3 files changed, 31 insertions(+) diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index c24f0895c..265ba97c4 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -302,6 +302,7 @@ const struct promex_metric promex_st_metrics[ST_F_TOTAL_FIELDS] = { [ST_F_NEED_CONN_EST]= { .n = IST("need_connections_current"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_SRV_METRIC) }, [ST_F_UWEIGHT] = { .n = IST("uweight"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, [ST_F_AGG_SRV_STATUS ] = { .n = IST("agg_server_status"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_BACK_METRIC ) }, + [ST_F_AGG_SRV_CHECK_STATUS] = { .n = IST("agg_server_check_status"), .type = PROMEX_MT_GAUGE,.flags = ( PROMEX_FL_BACK_METRIC ) }, }; /* Description of overridden stats fields */ @@ -811,6 +812,7 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) double secs; enum promex_back_state bkd_state; enum promex_srv_state srv_state; + enum healthcheck_status srv_check_status; for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) @@ -819,6 +821,8 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) while (ctx->px) { struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; unsigned int srv_state_count[PROMEX_SRV_STATE_COUNT] = { 0 }; + unsigned int srv_check_count[HCHK_STATUS_SIZE] = { 0 }; + const char *check_state; px = ctx->px; @@ -852,6 +856,28 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) } ctx->obj_state = 0; goto next_px; + case ST_F_AGG_SRV_CHECK_STATUS: + if (!px->srv) + goto next_px; + sv = px->srv; + while (sv) { + srv_check_status = sv->check.status; + srv_check_count[srv_check_status] += 1; + sv = sv->next; + } + for (; ctx->obj_state < HCHK_STATUS_SIZE; ctx->obj_state++) { + if (get_check_status_result(ctx->obj_state) < CHK_RES_FAILED) + continue; + val = mkf_u32(FO_STATUS, srv_check_count[ctx->obj_state]); + check_state = get_check_status_info(ctx->obj_state); + labels[1].name = ist("state"); + labels[1].value = ist(check_state); + if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], + &val, labels, &out, max)) + goto full; + } + ctx->obj_state = 0; + goto next_px; case ST_F_STATUS: bkd_state = ((px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0); for (; ctx->obj_state < PROMEX_BACK_STATE_COUNT; ctx->obj_state++) { diff --git a/include/haproxy/stats-t.h b/include/haproxy/stats-t.h index babea31e1..66bacd065 100644 --- a/include/haproxy/stats-t.h +++ b/include/haproxy/stats-t.h @@ -456,6 +456,7 @@ enum stat_field { ST_F_NEED_CONN_EST, ST_F_UWEIGHT, ST_F_AGG_SRV_STATUS , + ST_F_AGG_SRV_CHECK_STATUS, /* must always be the last one */ ST_F_TOTAL_FIELDS
[PATCH 0/2] BUG/MINOR: promex: fix haproxy_backend_agg_server_check_status
As described in github issue #1312, the first intention of patch 42d7c402d was to aggregate haproxy_server_check_status. But we aggregated haproxy_server_status instead. To fix that, rename haproxy_backend_agg_server_check_status to haproxy_backend_agg_server_status and use right data source for haproxy_backend_agg_server_check_status. Cedric Paillet (2): BUG/MINOR: promex: rename haproxy_backend_agg_server_check_status MINOR: promex: reintroduce haproxy_backend_agg_server_check_status addons/promex/service-prometheus.c | 28 +++- include/haproxy/stats-t.h | 1 + src/stats.c| 4 3 files changed, 32 insertions(+), 1 deletion(-) -- 2.25.1