summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0417450)
raw | patch | inline | side by side (parent: 0417450)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 23 Feb 2008 18:51:59 +0000 (19:51 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 23 Feb 2008 18:51:59 +0000 (19:51 +0100) |
They can not use the consolidation functions `AVERAGE', `MIN', `MAX' and `LAST'
just as you know them from RRDTool.
just as you know them from RRDTool.
src/utils_match.c | patch | blob | history | |
src/utils_match.h | patch | blob | history |
diff --git a/src/utils_match.c b/src/utils_match.c
index d4ac05a2e3fb8edcc45da5ca24b33e89b39f7798..4485f273d8f29447e44dcb086074db466bbc9535 100644 (file)
--- a/src/utils_match.c
+++ b/src/utils_match.c
{
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;
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 5108e966a5c06fda1a6b2a25f519f652bda97414..da9f1bcd2cf72721060979b786ded90dbbdcf5af 100644 (file)
--- a/src/utils_match.h
+++ b/src/utils_match.h
/*
* 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
{
int ds_type;
value_t value;
+ unsigned int values_num;
};
typedef struct cu_match_value_s cu_match_value_t;