From b42b7eaaaa3d2b375dc17b52f8858c0ebe2f5f40 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 30 Oct 2016 21:40:04 +0100 Subject: [PATCH] tail plugin: Implement the "GaugePersist" type. --- src/collectd.conf.pod | 7 +++++++ src/daemon/utils_match.c | 11 +++++------ src/daemon/utils_match.h | 1 + src/tail.c | 2 ++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 761351e4..dff0e370 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -7144,6 +7144,13 @@ Use the greatest number only. Use the last number found. +=item B + +Use the last number found. The number if not reset at the end of an interval. +It is continously reported until another number if matched. This is intended +for cases in which only state changes are reported, for example a thermometer +that only reports the temperature when it changes. + =item B =item B diff --git a/src/daemon/utils_match.c b/src/daemon/utils_match.c index 914b6e27..31ee6df2 100644 --- a/src/daemon/utils_match.c +++ b/src/daemon/utils_match.c @@ -295,14 +295,13 @@ cu_match_t *match_create_simple (const char *regex, void match_value_reset (cu_match_value_t *mv) { - if (mv == NULL) + if ((mv == NULL) + || ((mv->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) == 0) + || ((mv->ds_type & UTILS_MATCH_CF_GAUGE_PERSIST) != 0)) return; - if (mv->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) - { - mv->value.gauge = NAN; - mv->values_num = 0; - } + mv->value.gauge = NAN; + mv->values_num = 0; } /* }}} void match_value_reset */ void match_destroy (cu_match_t *obj) diff --git a/src/daemon/utils_match.h b/src/daemon/utils_match.h index a1d10020..d43ae3b3 100644 --- a/src/daemon/utils_match.h +++ b/src/daemon/utils_match.h @@ -46,6 +46,7 @@ #define UTILS_MATCH_CF_GAUGE_LAST 0x08 #define UTILS_MATCH_CF_GAUGE_INC 0x10 #define UTILS_MATCH_CF_GAUGE_ADD 0x20 +#define UTILS_MATCH_CF_GAUGE_PERSIST 0x40 #define UTILS_MATCH_CF_COUNTER_SET 0x01 #define UTILS_MATCH_CF_COUNTER_ADD 0x02 diff --git a/src/tail.c b/src/tail.c index 74fdf84a..0ac8be7c 100644 --- a/src/tail.c +++ b/src/tail.c @@ -85,6 +85,8 @@ static int ctail_config_add_match_dstype (ctail_config_match_t *cm, cm->flags |= UTILS_MATCH_CF_GAUGE_INC; else if (strcasecmp ("GaugeAdd", ci->values[0].value.string) == 0) cm->flags |= UTILS_MATCH_CF_GAUGE_ADD; + else if (strcasecmp ("GaugePersist", ci->values[0].value.string) == 0) + cm->flags |= UTILS_MATCH_CF_GAUGE_PERSIST; else cm->flags = 0; } -- 2.30.2