projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Request kernel version in reported issues
[collectd.git]
/
src
/
disk.c
diff --git
a/src/disk.c
b/src/disk.c
index
004ce9e
..
c78df4e
100644
(file)
--- a/
src/disk.c
+++ b/
src/disk.c
@@
-82,7
+82,7
@@
static mach_port_t io_master_port = MACH_PORT_NULL;
/* This defaults to false for backwards compatibility. Please fix in the next
* major version. */
static mach_port_t io_master_port = MACH_PORT_NULL;
/* This defaults to false for backwards compatibility. Please fix in the next
* major version. */
-static
_Bool use_bsd_name = 0
;
+static
bool use_bsd_name
;
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
@@
-106,9
+106,9
@@
typedef struct diskstats {
derive_t avg_read_time;
derive_t avg_write_time;
derive_t avg_read_time;
derive_t avg_write_time;
-
_B
ool has_merged;
-
_B
ool has_in_progress;
-
_B
ool has_io_time;
+
b
ool has_merged;
+
b
ool has_in_progress;
+
b
ool has_io_time;
struct diskstats *next;
} diskstats_t;
struct diskstats *next;
} diskstats_t;
@@
-120,10
+120,13
@@
static struct gmesh geom_tree;
/* #endif KERNEL_FREEBSD */
#elif HAVE_LIBKSTAT
/* #endif KERNEL_FREEBSD */
#elif HAVE_LIBKSTAT
+#if HAVE_KSTAT_H
+#include <kstat.h>
+#endif
#define MAX_NUMDISK 1024
extern kstat_ctl_t *kc;
static kstat_t *ksp[MAX_NUMDISK];
#define MAX_NUMDISK 1024
extern kstat_ctl_t *kc;
static kstat_t *ksp[MAX_NUMDISK];
-static int numdisk
= 0
;
+static int numdisk;
/* #endif HAVE_LIBKSTAT */
#elif defined(HAVE_LIBSTATGRAB)
/* #endif HAVE_LIBKSTAT */
#elif defined(HAVE_LIBSTATGRAB)
@@
-139,10
+142,10
@@
static int pnumdisk;
#error "No applicable input method."
#endif
#error "No applicable input method."
#endif
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
#include <libudev.h>
#include <libudev.h>
-static char *conf_udev_name_attr
= NULL
;
+static char *conf_udev_name_attr;
static struct udev *handle_udev;
#endif
static struct udev *handle_udev;
#endif
@@
-150,7
+153,7
@@
static const char *config_keys[] = {"Disk", "UseBSDName", "IgnoreSelected",
"UdevNameAttr"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
"UdevNameAttr"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
-static ignorelist_t *ignorelist
= NULL
;
+static ignorelist_t *ignorelist;
static int disk_config(const char *key, const char *value) {
if (ignorelist == NULL)
static int disk_config(const char *key, const char *value) {
if (ignorelist == NULL)
@@
-167,13
+170,13
@@
static int disk_config(const char *key, const char *value) {
ignorelist_set_invert(ignorelist, invert);
} else if (strcasecmp("UseBSDName", key) == 0) {
#if HAVE_IOKIT_IOKITLIB_H
ignorelist_set_invert(ignorelist, invert);
} else if (strcasecmp("UseBSDName", key) == 0) {
#if HAVE_IOKIT_IOKITLIB_H
- use_bsd_name = IS_TRUE(value)
? 1 : 0
;
+ use_bsd_name = IS_TRUE(value);
#else
WARNING("disk plugin: The \"UseBSDName\" option is only supported "
"on Mach / Mac OS X and will be ignored.");
#endif
} else if (strcasecmp("UdevNameAttr", key) == 0) {
#else
WARNING("disk plugin: The \"UseBSDName\" option is only supported "
"on Mach / Mac OS X and will be ignored.");
#endif
} else if (strcasecmp("UdevNameAttr", key) == 0) {
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
if (conf_udev_name_attr != NULL) {
free(conf_udev_name_attr);
conf_udev_name_attr = NULL;
if (conf_udev_name_attr != NULL) {
free(conf_udev_name_attr);
conf_udev_name_attr = NULL;
@@
-209,7
+212,7
@@
static int disk_init(void) {
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
if (conf_udev_name_attr != NULL) {
handle_udev = udev_new();
if (handle_udev == NULL) {
if (conf_udev_name_attr != NULL) {
handle_udev = udev_new();
if (handle_udev == NULL) {
@@
-217,7
+220,7
@@
static int disk_init(void) {
return -1;
}
}
return -1;
}
}
-#endif /* HAVE_UDEV_H */
+#endif /* HAVE_
LIB
UDEV_H */
/* #endif KERNEL_LINUX */
#elif KERNEL_FREEBSD
/* #endif KERNEL_LINUX */
#elif KERNEL_FREEBSD
@@
-260,10
+263,10
@@
static int disk_init(void) {
static int disk_shutdown(void) {
#if KERNEL_LINUX
static int disk_shutdown(void) {
#if KERNEL_LINUX
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
if (handle_udev != NULL)
udev_unref(handle_udev);
if (handle_udev != NULL)
udev_unref(handle_udev);
-#endif /* HAVE_UDEV_H */
+#endif /* HAVE_
LIB
UDEV_H */
#endif /* KERNEL_LINUX */
return 0;
} /* int disk_shutdown */
#endif /* KERNEL_LINUX */
return 0;
} /* int disk_shutdown */
@@
-300,9
+303,7
@@
static void submit_io_time(char const *plugin_instance, derive_t io_time,
plugin_dispatch_values(&vl);
} /* void submit_io_time */
plugin_dispatch_values(&vl);
} /* void submit_io_time */
-#endif /* KERNEL_FREEBSD || KERNEL_LINUX */
-#if KERNEL_LINUX
static void submit_in_progress(char const *disk_name, gauge_t in_progress) {
value_list_t vl = VALUE_LIST_INIT;
static void submit_in_progress(char const *disk_name, gauge_t in_progress) {
value_list_t vl = VALUE_LIST_INIT;
@@
-314,7
+315,9
@@
static void submit_in_progress(char const *disk_name, gauge_t in_progress) {
plugin_dispatch_values(&vl);
}
plugin_dispatch_values(&vl);
}
+#endif /* KERNEL_FREEBSD || KERNEL_LINUX */
+#if KERNEL_LINUX
static counter_t disk_calc_time_incr(counter_t delta_time,
counter_t delta_ops) {
double interval = CDTIME_T_TO_DOUBLE(plugin_get_interval());
static counter_t disk_calc_time_incr(counter_t delta_time,
counter_t delta_ops) {
double interval = CDTIME_T_TO_DOUBLE(plugin_get_interval());
@@
-325,7
+328,7
@@
static counter_t disk_calc_time_incr(counter_t delta_time,
}
#endif
}
#endif
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
/**
* Attempt to provide an rename disk instance from an assigned udev attribute.
*
/**
* Attempt to provide an rename disk instance from an assigned udev attribute.
*
@@
-541,6
+544,7
@@
static int disk_read(void) {
const char *disk_name;
long double read_time, write_time, busy_time, total_duration;
const char *disk_name;
long double read_time, write_time, busy_time, total_duration;
+ uint64_t queue_length;
for (retry = 0, dirty = 1; retry < 5 && dirty == 1; retry++) {
if (snap != NULL)
for (retry = 0, dirty = 1; retry < 5 && dirty == 1; retry++) {
if (snap != NULL)
@@
-643,10
+647,12
@@
static int disk_read(void) {
}
if (devstat_compute_statistics(snap_iter, NULL, 1.0, DSM_TOTAL_BUSY_TIME,
&busy_time, DSM_TOTAL_DURATION,
}
if (devstat_compute_statistics(snap_iter, NULL, 1.0, DSM_TOTAL_BUSY_TIME,
&busy_time, DSM_TOTAL_DURATION,
- &total_duration, DSM_NONE) != 0) {
+ &total_duration, DSM_QUEUE_LENGTH,
+ &queue_length, DSM_NONE) != 0) {
WARNING("%s", devstat_errbuf);
} else {
submit_io_time(disk_name, busy_time, total_duration);
WARNING("%s", devstat_errbuf);
} else {
submit_io_time(disk_name, busy_time, total_duration);
+ submit_in_progress(disk_name, (gauge_t)queue_length);
}
}
geom_stats_snapshot_free(snap);
}
}
geom_stats_snapshot_free(snap);
@@
-657,7
+663,6
@@
static int disk_read(void) {
char *fields[32];
int numfields;
char *fields[32];
int numfields;
- int fieldshift = 0;
int minor = 0;
int minor = 0;
@@
-678,14
+683,8
@@
static int disk_read(void) {
diskstats_t *ds, *pre_ds;
if ((fh = fopen("/proc/diskstats", "r")) == NULL) {
diskstats_t *ds, *pre_ds;
if ((fh = fopen("/proc/diskstats", "r")) == NULL) {
- fh = fopen("/proc/partitions", "r");
- if (fh == NULL) {
- ERROR("disk plugin: fopen (/proc/{diskstats,partitions}) failed.");
- return -1;
- }
-
- /* Kernel is 2.4.* */
- fieldshift = 1;
+ ERROR("disk plugin: fopen(\"/proc/diskstats\"): %s", STRERRNO);
+ return -1;
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
@@
-694,12
+693,13
@@
static int disk_read(void) {
numfields = strsplit(buffer, fields, 32);
numfields = strsplit(buffer, fields, 32);
- if ((numfields != (14 + fieldshift)) && (numfields != 7))
+ /* need either 7 fields (partition) or at least 14 fields */
+ if ((numfields != 7) && (numfields < 14))
continue;
minor = atoll(fields[1]);
continue;
minor = atoll(fields[1]);
- disk_name = fields[2
+ fieldshift
];
+ disk_name = fields[2];
for (ds = disklist, pre_ds = disklist; ds != NULL;
pre_ds = ds, ds = ds->next)
for (ds = disklist, pre_ds = disklist; ds != NULL;
pre_ds = ds, ds = ds->next)
@@
-728,28
+728,26
@@
static int disk_read(void) {
read_sectors = atoll(fields[4]);
write_ops = atoll(fields[5]);
write_sectors = atoll(fields[6]);
read_sectors = atoll(fields[4]);
write_ops = atoll(fields[5]);
write_sectors = atoll(fields[6]);
- } else if (numfields == (14 + fieldshift)) {
- read_ops = atoll(fields[3 + fieldshift]);
- write_ops = atoll(fields[7 + fieldshift]);
+ } else {
+ assert(numfields >= 14);
+ read_ops = atoll(fields[3]);
+ write_ops = atoll(fields[7]);
- read_sectors = atoll(fields[5
+ fieldshift
]);
- write_sectors = atoll(fields[9
+ fieldshift
]);
+ read_sectors = atoll(fields[5]);
+ write_sectors = atoll(fields[9]);
- if (
(fieldshift == 0) || (minor == 0)
) {
+ if (
minor == 0
) {
is_disk = 1;
is_disk = 1;
- read_merged = atoll(fields[4
+ fieldshift
]);
- read_time = atoll(fields[6
+ fieldshift
]);
- write_merged = atoll(fields[8
+ fieldshift
]);
- write_time = atoll(fields[10
+ fieldshift
]);
+ read_merged = atoll(fields[4]);
+ read_time = atoll(fields[6]);
+ write_merged = atoll(fields[8]);
+ write_time = atoll(fields[10]);
- in_progress = atof(fields[11
+ fieldshift
]);
+ in_progress = atof(fields[11]);
- io_time = atof(fields[12
+ fieldshift
]);
- weighted_time = atof(fields[13
+ fieldshift
]);
+ io_time = atof(fields[12]);
+ weighted_time = atof(fields[13]);
}
}
- } else {
- DEBUG("numfields = %i; => unknown file format.", numfields);
- continue;
}
{
}
{
@@
-814,13
+812,13
@@
static int disk_read(void) {
ds->write_time = write_time;
if (read_merged || write_merged)
ds->write_time = write_time;
if (read_merged || write_merged)
- ds->has_merged =
1
;
+ ds->has_merged =
true
;
if (in_progress)
if (in_progress)
- ds->has_in_progress =
1
;
+ ds->has_in_progress =
true
;
if (io_time)
if (io_time)
- ds->has_io_time =
1
;
+ ds->has_io_time =
true
;
} /* if (is_disk) */
} /* if (is_disk) */
@@
-841,7
+839,7
@@
static int disk_read(void) {
output_name = disk_name;
output_name = disk_name;
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
char *alt_name = NULL;
if (conf_udev_name_attr != NULL) {
alt_name =
char *alt_name = NULL;
if (conf_udev_name_attr != NULL) {
alt_name =
@@
-852,7
+850,7
@@
static int disk_read(void) {
#endif
if (ignorelist_match(ignorelist, output_name) != 0) {
#endif
if (ignorelist_match(ignorelist, output_name) != 0) {
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
/* release udev-based alternate name, if allocated */
sfree(alt_name);
#endif
/* release udev-based alternate name, if allocated */
sfree(alt_name);
#endif
@@
-878,7
+876,7
@@
static int disk_read(void) {
submit_io_time(output_name, io_time, weighted_time);
} /* if (is_disk) */
submit_io_time(output_name, io_time, weighted_time);
} /* if (is_disk) */
-#if HAVE_UDEV_H
+#if HAVE_
LIB
UDEV_H
/* release udev-based alternate name, if allocated */
sfree(alt_name);
#endif
/* release udev-based alternate name, if allocated */
sfree(alt_name);
#endif