summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aed8c4a)
raw | patch | inline | side by side (parent: aed8c4a)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 28 Oct 2007 16:48:29 +0000 (17:48 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 28 Oct 2007 16:48:29 +0000 (17:48 +0100) |
and calculate the difference correctly.
src/utils_cache.c | patch | blob | history | |
src/utils_cache.h | patch | blob | history |
diff --git a/src/utils_cache.c b/src/utils_cache.c
index 5ecb83cfa015cc6b4cb606c1ad499676d6ebb2f6..79989a07aedf0247712ca0805499e750de1bec35 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
{
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;
}
diff --git a/src/utils_cache.h b/src/utils_cache.h
index 914540577f4f0e7965512cba74b4d3c96d9b12b7..8d1c75496ea5a1a1898e02d19d01a104347da093 100644 (file)
--- a/src/utils_cache.h
+++ b/src/utils_cache.h
/**
- * 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