summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c1dd86d)
raw | patch | inline | side by side (parent: c1dd86d)
author | octo <octo> | |
Wed, 14 Jun 2006 09:40:02 +0000 (09:40 +0000) | ||
committer | octo <octo> | |
Wed, 14 Jun 2006 09:40:02 +0000 (09:40 +0000) |
When `{read,write}-sectors' hit the 32 bit boundary, `atoi' would always return
LONG_MAX, resulting in the same counter-value being logged over and over again,
resulting in zero-entries in the RRD file.
Thanks to James Valente for reporting this bug and providing much debugging
information :)
LONG_MAX, resulting in the same counter-value being logged over and over again,
resulting in zero-entries in the RRD file.
Thanks to James Valente for reporting this bug and providing much debugging
information :)
src/disk.c | patch | blob | history |
diff --git a/src/disk.c b/src/disk.c
index 6aefbc7dfb15a65313b9eb580b90abc73a3f930a..ca3531eb5a14748327570bdd76d19618a90fa13b 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
/* This overflows in roughly 1361 year */
unsigned int poll_count;
- unsigned int read_sectors;
- unsigned int write_sectors;
+ unsigned long long read_sectors;
+ unsigned long long write_sectors;
unsigned long long read_bytes;
unsigned long long write_bytes;
} diskstats_t;
static diskstats_t *disklist;
+static int min_poll_count;
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
- /* No init needed */
+ int step;
+ int heartbeat;
+
+ step = atoi (COLLECTD_STEP);
+ heartbeat = atoi (COLLECTD_HEARTBEAT);
+
+ assert (step > 0);
+ assert (heartbeat >= step);
+
+ min_poll_count = 1 + (heartbeat / step);
+ DBG ("min_poll_count = %i;", min_poll_count);
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
write_time) >= BUFSIZE)
return;
+ DBG ("disk_name = %s; buf = %s;",
+ disk_name, buf);
+
plugin_submit (MODULE_NAME, disk_name, buf);
}
int major = 0;
int minor = 0;
- unsigned int read_sectors;
- unsigned int write_sectors;
-
- unsigned long long read_count = 0;
- unsigned long long read_merged = 0;
- unsigned long long read_bytes = 0;
- unsigned long long read_time = 0;
- unsigned long long write_count = 0;
- unsigned long long write_merged = 0;
- unsigned long long write_bytes = 0;
- unsigned long long write_time = 0;
+ unsigned long long read_sectors = 0ULL;
+ unsigned long long write_sectors = 0ULL;
+
+ unsigned long long read_count = 0ULL;
+ unsigned long long read_merged = 0ULL;
+ unsigned long long read_bytes = 0ULL;
+ unsigned long long read_time = 0ULL;
+ unsigned long long write_count = 0ULL;
+ unsigned long long write_merged = 0ULL;
+ unsigned long long write_bytes = 0ULL;
+ unsigned long long write_time = 0ULL;
int is_disk = 0;
diskstats_t *ds, *pre_ds;
{
/* Kernel 2.6, Partition */
read_count = atoll (fields[3]);
- read_sectors = atoi (fields[4]);
+ read_sectors = atoll (fields[4]);
write_count = atoll (fields[5]);
- write_sectors = atoi (fields[6]);
+ write_sectors = atoll (fields[6]);
}
else if (numfields == (14 + fieldshift))
{
read_count = atoll (fields[3 + fieldshift]);
write_count = atoll (fields[7 + fieldshift]);
- read_sectors = atoi (fields[5 + fieldshift]);
- write_sectors = atoi (fields[9 + fieldshift]);
+ read_sectors = atoll (fields[5 + fieldshift]);
+ write_sectors = atoll (fields[9 + fieldshift]);
if ((fieldshift == 0) || (minor == 0))
{
}
else
{
+ DBG ("numfields = %i; => unknown file format.", numfields);
continue;
}
-
- if (read_sectors >= ds->read_sectors)
- ds->read_bytes += 512 * (read_sectors - ds->read_sectors);
+ /* If the counter wraps around, it's only 32 bits.. */
+ if (read_sectors < ds->read_sectors)
+ ds->read_bytes += 512 * ((0xFFFFFFFF - ds->read_sectors) + read_sectors);
else
- ds->read_bytes += 512 * ((UINT_MAX - ds->read_sectors) + read_sectors);
+ ds->read_bytes += 512 * (read_sectors - ds->read_sectors);
- if (write_sectors >= ds->write_sectors)
- ds->write_bytes += 512 * (write_sectors - ds->write_sectors);
+ if (write_sectors < ds->write_sectors)
+ ds->write_bytes += 512 * ((0xFFFFFFFF - ds->write_sectors) + write_sectors);
else
- ds->write_bytes += 512 * ((UINT_MAX - ds->write_sectors) + write_sectors);
+ ds->write_bytes += 512 * (write_sectors - ds->write_sectors);
ds->read_sectors = read_sectors;
ds->write_sectors = write_sectors;
/* Don't write to the RRDs if we've just started.. */
ds->poll_count++;
- if (ds->poll_count <= 6)
+ if (ds->poll_count <= min_poll_count)
+ {
+ DBG ("(ds->poll_count = %i) <= (min_poll_count = %i); => Not writing.",
+ ds->poll_count, min_poll_count);
continue;
+ }
if ((read_count == 0) && (write_count == 0))
+ {
+ DBG ("((read_count == 0) && (write_count == 0)); => Not writing.");
continue;
+ }
if (is_disk)
disk_submit (disk_name, read_count, read_merged, read_bytes, read_time,