char buffer[1024];
char *fields[32];
+ static unsigned int poll_count = 0;
derive_t read_sectors = 0;
derive_t write_sectors = 0;
return -1;
}
+ poll_count++;
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
- char *disk_name;
- char *output_name;
-
int numfields = strsplit(buffer, fields, 32);
/* need either 7 fields (partition) or at least 14 fields */
if ((numfields != 7) && (numfields < 14))
continue;
- disk_name = fields[2];
+ char *disk_name = fields[2];
for (ds = disklist, pre_ds = disklist; ds != NULL;
pre_ds = ds, ds = ds->next)
break;
if (ds == NULL) {
- if ((ds = (diskstats_t *)calloc(1, sizeof(diskstats_t))) == NULL)
+ if ((ds = calloc(1, sizeof(*ds))) == NULL)
continue;
if ((ds->name = strdup(disk_name)) == NULL) {
} /* if (is_disk) */
- /* Don't write to the RRDs if we've just started.. */
- ds->poll_count++;
- if (ds->poll_count <= 2) {
- DEBUG("disk plugin: (ds->poll_count = %i) <= "
- "(min_poll_count = 2); => Not writing.",
- ds->poll_count);
+ /* Skip first cycle for newly-added disk */
+ if (ds->poll_count == 0) {
+ DEBUG("disk plugin: (ds->poll_count = 0) => Skipping.");
+ ds->poll_count = poll_count;
continue;
}
+ ds->poll_count = poll_count;
if ((read_ops == 0) && (write_ops == 0)) {
DEBUG("disk plugin: ((read_ops == 0) && "
continue;
}
- output_name = disk_name;
+ char *output_name = disk_name;
#if HAVE_LIBUDEV_H
char *alt_name = NULL;
#endif
} /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
+ /* Remove disks that have disappeared from diskstats */
+ for (ds = disklist, pre_ds = disklist; ds != NULL;) {
+ /* Disk exists */
+ if (ds->poll_count == poll_count) {
+ pre_ds = ds;
+ ds = ds->next;
+ continue;
+ }
+
+ /* Disk is missing, remove it */
+ diskstats_t *missing_ds = ds;
+ if (ds == disklist) {
+ pre_ds = disklist = ds->next;
+ } else {
+ pre_ds->next = ds->next;
+ }
+ ds = ds->next;
+
+ DEBUG("disk plugin: Disk %s disappeared.", missing_ds->name);
+ free(missing_ds->name);
+ free(missing_ds);
+ }
fclose(fh);
/* #endif defined(KERNEL_LINUX) */
}
if (numdisk != pnumdisk || stat_disk == NULL) {
- if (stat_disk != NULL)
- free(stat_disk);
- stat_disk = (perfstat_disk_t *)calloc(numdisk, sizeof(perfstat_disk_t));
+ free(stat_disk);
+ stat_disk = calloc(numdisk, sizeof(*stat_disk));
}
pnumdisk = numdisk;