From: Florian Forster Date: Sat, 23 Feb 2008 18:51:59 +0000 (+0100) Subject: src/utils_match.[ch]: Improved the handling of gauge values. X-Git-Tag: collectd-4.4.0~89^2~5 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7b1cd2f1da2ba207599a6537e5cc6328f07a9d20;p=collectd.git src/utils_match.[ch]: Improved the handling of gauge values. They can not use the consolidation functions `AVERAGE', `MIN', `MAX' and `LAST' just as you know them from RRDTool. --- diff --git a/src/utils_match.c b/src/utils_match.c index d4ac05a2..4485f273 100644 --- a/src/utils_match.c +++ b/src/utils_match.c @@ -46,7 +46,7 @@ static int default_callback (const char *str, void *user_data) { cu_match_value_t *data = (cu_match_value_t *) user_data; - if (data->ds_type == UTILS_MATCH_DS_TYPE_GAUGE) + if (data->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) { gauge_t value; char *endptr = NULL; @@ -55,29 +55,66 @@ static int default_callback (const char *str, void *user_data) if (str == endptr) return (-1); - data->value.gauge = value; + if ((data->values_num == 0) + || (data->ds_type & UTILS_MATCH_CF_GAUGE_LAST)) + { + data->value.gauge = value; + } + else if (data->ds_type & UTILS_MATCH_CF_GAUGE_AVERAGE) + { + double f = ((double) data->values_num) + / ((double) (data->values_num + 1)); + data->value.gauge = (data->value.gauge * f) + (value * (1.0 - f)); + } + else if (data->ds_type & UTILS_MATCH_CF_GAUGE_MIN) + { + if (data->value.gauge > value) + data->value.gauge = value; + } + else if (data->ds_type & UTILS_MATCH_CF_GAUGE_MAX) + { + if (data->value.gauge < value) + data->value.gauge = value; + } + else + { + ERROR ("utils_match: default_callback: obj->ds_type is invalid!"); + return (-1); + } + + data->values_num++; } - else if ((data->ds_type == UTILS_MATCH_DS_TYPE_COUNTER_SET) - || (data->ds_type == UTILS_MATCH_DS_TYPE_COUNTER_ADD)) + else if (data->ds_type & UTILS_MATCH_DS_TYPE_COUNTER) { counter_t value; char *endptr = NULL; + if (data->ds_type & UTILS_MATCH_CF_COUNTER_INC) + { + data->value.counter++; + data->values_num++; + return (0); + } + value = strtoll (str, &endptr, 0); if (str == endptr) return (-1); - if (data->ds_type == UTILS_MATCH_DS_TYPE_COUNTER_SET) + if (data->ds_type & UTILS_MATCH_CF_COUNTER_SET) data->value.counter = value; - else + else if (data->ds_type & UTILS_MATCH_CF_COUNTER_ADD) data->value.counter += value; - } - else if (data->ds_type == UTILS_MATCH_DS_TYPE_COUNTER_INC) - { - data->value.counter++; + else + { + ERROR ("utils_match: default_callback: obj->ds_type is invalid!"); + return (-1); + } + + data->values_num++; } else { + ERROR ("utils_match: default_callback: obj->ds_type is invalid!"); return (-1); } diff --git a/src/utils_match.h b/src/utils_match.h index 5108e966..da9f1bcd 100644 --- a/src/utils_match.h +++ b/src/utils_match.h @@ -28,10 +28,17 @@ /* * Defines */ -#define UTILS_MATCH_DS_TYPE_GAUGE 0 -#define UTILS_MATCH_DS_TYPE_COUNTER_SET 1 -#define UTILS_MATCH_DS_TYPE_COUNTER_ADD 2 -#define UTILS_MATCH_DS_TYPE_COUNTER_INC 3 +#define UTILS_MATCH_DS_TYPE_GAUGE 0x10 +#define UTILS_MATCH_DS_TYPE_COUNTER 0x20 + +#define UTILS_MATCH_CF_GAUGE_AVERAGE 0x01 +#define UTILS_MATCH_CF_GAUGE_MIN 0x02 +#define UTILS_MATCH_CF_GAUGE_MAX 0x04 +#define UTILS_MATCH_CF_GAUGE_LAST 0x08 + +#define UTILS_MATCH_CF_COUNTER_SET 0x01 +#define UTILS_MATCH_CF_COUNTER_ADD 0x02 +#define UTILS_MATCH_CF_COUNTER_INC 0x04 /* * Data types @@ -43,6 +50,7 @@ struct cu_match_value_s { int ds_type; value_t value; + unsigned int values_num; }; typedef struct cu_match_value_s cu_match_value_t;