{
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);
}
/*
* 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;