projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
write_tsdb: enable TCP keepalive on network socket
[collectd.git]
/
src
/
disk.c
diff --git
a/src/disk.c
b/src/disk.c
index
0d62488
..
d7eb0a5
100644
(file)
--- a/
src/disk.c
+++ b/
src/disk.c
@@
-22,6
+22,7
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
@@
-230,7
+231,16
@@
static int disk_init (void)
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
- /* do nothing */
+#if HAVE_LIBUDEV
+ if (conf_udev_name_attr != NULL)
+ {
+ handle_udev = udev_new();
+ if (handle_udev == NULL) {
+ ERROR ("disk plugin: udev_new() failed!");
+ return (-1);
+ }
+ }
+#endif /* HAVE_LIBUDEV */
/* #endif KERNEL_LINUX */
#elif KERNEL_FREEBSD
/* #endif KERNEL_LINUX */
#elif KERNEL_FREEBSD
@@
-272,6
+282,17
@@
static int disk_init (void)
return (0);
} /* int disk_init */
return (0);
} /* int disk_init */
+static int disk_shutdown (void)
+{
+#if KERNEL_LINUX
+#if HAVE_LIBUDEV
+ if (handle_udev != NULL)
+ udev_unref(handle_udev);
+#endif /* HAVE_LIBUDEV */
+#endif /* KERNEL_LINUX */
+ return (0);
+} /* int disk_shutdown */
+
static void disk_submit (const char *plugin_instance,
const char *type,
derive_t read, derive_t write)
static void disk_submit (const char *plugin_instance,
const char *type,
derive_t read, derive_t write)
@@
-690,10
+711,6
@@
static int disk_read (void)
fieldshift = 1;
}
fieldshift = 1;
}
-#if HAVE_LIBUDEV
- handle_udev = udev_new();
-#endif
-
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
char *disk_name;
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
char *disk_name;
@@
-867,13
+884,23
@@
static int disk_read (void)
output_name = disk_name;
#if HAVE_LIBUDEV
output_name = disk_name;
#if HAVE_LIBUDEV
- char *alt_name = disk_udev_attr_name (handle_udev, disk_name, conf_udev_name_attr);
- if (alt_name != NULL)
- output_name = alt_name;
+ char *alt_name = NULL;
+ if (conf_udev_name_attr != NULL)
+ {
+ alt_name = disk_udev_attr_name (handle_udev, disk_name, conf_udev_name_attr);
+ if (alt_name != NULL)
+ output_name = alt_name;
+ }
#endif
if (ignorelist_match (ignorelist, output_name) != 0)
#endif
if (ignorelist_match (ignorelist, output_name) != 0)
+ {
+#if HAVE_LIBUDEV
+ /* release udev-based alternate name, if allocated */
+ sfree (alt_name);
+#endif
continue;
continue;
+ }
if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
disk_submit (output_name, "disk_octets",
if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
disk_submit (output_name, "disk_octets",
@@
-904,9
+931,6
@@
static int disk_read (void)
#endif
} /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
#endif
} /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
-#if HAVE_LIBUDEV
- udev_unref(handle_udev);
-#endif
fclose (fh);
/* #endif defined(KERNEL_LINUX) */
fclose (fh);
/* #endif defined(KERNEL_LINUX) */
@@
-930,12
+954,11
@@
static int disk_read (void)
# error "kstat_io_t does not have the required members"
# endif
static kstat_io_t kio;
# error "kstat_io_t does not have the required members"
# endif
static kstat_io_t kio;
- int i;
if (kc == NULL)
return (-1);
if (kc == NULL)
return (-1);
- for (i = 0; i < numdisk; i++)
+ for (i
nt i
= 0; i < numdisk; i++)
{
if (kstat_read (kc, ksp[i], &kio) == -1)
continue;
{
if (kstat_read (kc, ksp[i], &kio) == -1)
continue;
@@
-973,13
+996,12
@@
static int disk_read (void)
# else
int disks;
#endif
# else
int disks;
#endif
- int counter;
char name[DATA_MAX_NAME_LEN];
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
return (0);
char name[DATA_MAX_NAME_LEN];
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
return (0);
- for (
counter=
0; counter < disks; counter++) {
+ for (
int counter =
0; counter < disks; counter++) {
strncpy(name, ds->disk_name, sizeof(name));
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
strncpy(name, ds->disk_name, sizeof(name));
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
@@
-1002,7
+1024,6
@@
static int disk_read (void)
derive_t write_ops;
perfstat_id_t firstpath;
int rnumdisk;
derive_t write_ops;
perfstat_id_t firstpath;
int rnumdisk;
- int i;
if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
{
if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
{
@@
-1028,7
+1049,7
@@
static int disk_read (void)
return (-1);
}
return (-1);
}
- for (i = 0; i < rnumdisk; i++)
+ for (i
nt i
= 0; i < rnumdisk; i++)
{
if (ignorelist_match (ignorelist, stat_disk[i].name) != 0)
continue;
{
if (ignorelist_match (ignorelist, stat_disk[i].name) != 0)
continue;
@@
-1057,5
+1078,6
@@
void module_register (void)
plugin_register_config ("disk", disk_config,
config_keys, config_keys_num);
plugin_register_init ("disk", disk_init);
plugin_register_config ("disk", disk_config,
config_keys, config_keys_num);
plugin_register_init ("disk", disk_init);
+ plugin_register_shutdown ("disk", disk_shutdown);
plugin_register_read ("disk", disk_read);
} /* void module_register */
plugin_register_read ("disk", disk_read);
} /* void module_register */