From: Florian Forster Date: Wed, 3 Sep 2014 07:10:00 +0000 (+0200) Subject: src/utils_match.[ch]: Implement match_value_reset(). X-Git-Tag: collectd-5.3.2~42 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0f877a368c1c339386add57c573094855457eefe;p=collectd.git src/utils_match.[ch]: Implement match_value_reset(). This is called from the curl and memcachec plugins. Previously, gauge average, minimum and maximum values were calculated since the start of the daemon, rather than per-interval. This is not the documented functionality. Fixes: #663 --- diff --git a/src/curl.c b/src/curl.c index e2c4a132..0d4677fd 100644 --- a/src/curl.c +++ b/src/curl.c @@ -650,6 +650,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */ } cc_submit (wp, wm, mv); + match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ return (0); diff --git a/src/memcachec.c b/src/memcachec.c index c57a8312..7c8528d5 100644 --- a/src/memcachec.c +++ b/src/memcachec.c @@ -500,6 +500,7 @@ static int cmc_read_page (web_page_t *wp) /* {{{ */ } cmc_submit (wp, wm, mv); + match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ sfree (wp->buffer); diff --git a/src/utils_match.c b/src/utils_match.c index 062bcfe3..bb53a9a3 100644 --- a/src/utils_match.c +++ b/src/utils_match.c @@ -1,6 +1,6 @@ /** * collectd - src/utils_match.c - * Copyright (C) 2008 Florian octo Forster + * Copyright (C) 2008-2014 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -279,6 +279,18 @@ cu_match_t *match_create_simple (const char *regex, return (obj); } /* cu_match_t *match_create_simple */ +void match_value_reset (cu_match_value_t *mv) +{ + if (mv == NULL) + return; + + if (mv->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) + { + mv->value.gauge = NAN; + mv->values_num = 0; + } +} /* }}} void match_value_reset */ + void match_destroy (cu_match_t *obj) { if (obj == NULL) diff --git a/src/utils_match.h b/src/utils_match.h index 36abe30c..24517b3a 100644 --- a/src/utils_match.h +++ b/src/utils_match.h @@ -1,6 +1,6 @@ /** * collectd - src/utils_match.h - * Copyright (C) 2008 Florian octo Forster + * Copyright (C) 2008-2014 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -119,6 +119,17 @@ cu_match_t *match_create_simple (const char *regex, /* * NAME + * match_value_reset + * + * DESCRIPTION + * Resets the internal state, if applicable. This function must be called + * after each iteration for "simple" matches, usually after dispatching the + * metrics. + */ +void match_value_reset (cu_match_value_t *mv); + +/* + * NAME * match_destroy * * DESCRIPTION