{
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;
}
/**
- * collectd - src/utils_cache.c
+ * collectd - src/utils_cache.h
* Copyright (C) 2007 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it