diff --git a/src/utils_cache.c b/src/utils_cache.c
index 5ecb83cfa015cc6b4cb606c1ad499676d6ebb2f6..9349a1f4a1c9364f8b170a1e324011a818f34167 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
} cache_entry_t;
static avl_tree_t *cache_tree = NULL;
-static pthread_mutex_t cache_lock;
+static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
static int cache_compare (const cache_entry_t *a, const cache_entry_t *b)
{
{
if (ds->ds[i].type == DS_TYPE_COUNTER)
{
- ce->values_gauge[i] = ((double) (vl->values[i].counter
- - ce->values_counter[i]))
+ counter_t diff;
+
+ /* check if the counter has wrapped around */
+ if (vl->values[i].counter < ce->values_counter[i])
+ {
+ if (ce->values_counter[i] <= 4294967295U)
+ diff = (4294967295U - ce->values_counter[i])
+ + vl->values[i].counter;
+ else
+ diff = (18446744073709551615ULL - ce->values_counter[i])
+ + vl->values[i].counter;
+ }
+ else /* counter has NOT wrapped around */
+ {
+ diff = vl->values[i].counter - ce->values_counter[i];
+ }
+
+ ce->values_gauge[i] = ((double) diff)
/ ((double) (vl->time - ce->last_update));
ce->values_counter[i] = vl->values[i].counter;
}