From 8f3d1d3a332b3c84204682bc6db6e3f2ad51997d Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Fri, 26 Jul 2024 23:38:28 -0400 Subject: [PATCH] in_node_exporter_metrics: systemd: treat states as boolean values. Signed-off-by: Phillip Whelan --- .../ne_systemd_linux.c | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_systemd_linux.c b/plugins/in_node_exporter_metrics/ne_systemd_linux.c index f0db5aa0fc7..2d9807812e0 100644 --- a/plugins/in_node_exporter_metrics/ne_systemd_linux.c +++ b/plugins/in_node_exporter_metrics/ne_systemd_linux.c @@ -459,25 +459,29 @@ static int ne_systemd_update_unit_state(struct flb_ne *ctx) } for(index = 0 ; index < 5 ; index++) { - cmt_gauge_add(ctx->systemd_unit_state, - timestamp, - 0, - 3, - (char *[]){ unit.name, + if (strcmp(unit_states[index], unit.active_state) == 0) { + cmt_gauge_set(ctx->systemd_unit_state, + timestamp, + 1, + 3, + (char *[]){ unit.name, unit_states[index], unit.type - }); + } + ); + } + else { + cmt_gauge_set(ctx->systemd_unit_state, + timestamp, + 0, + 3, + (char *[]){ unit.name, + unit_states[index], + unit.type + }); + } } - cmt_gauge_inc(ctx->systemd_unit_state, - timestamp, - 3, - (char *[]){ unit.name, - unit.active_state, - unit.type - }); - - if (unit.type != NULL) { free(unit.type); }