From d5ad844588fcbcdcdd36a889c94ac33d36c1d52c Mon Sep 17 00:00:00 2001 From: Oleg King Date: Mon, 5 May 2008 11:58:27 +0200 Subject: [PATCH] disk plugin: Add support for the statgrab library. --- configure.in | 1 + src/Makefile.am | 4 ++++ src/disk.c | 25 ++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index e834ffd6..e94730d8 100644 --- a/configure.in +++ b/configure.in @@ -2331,6 +2331,7 @@ fi # libstatgrab if test "x$with_libstatgrab" = "xyes" then + plugin_disk="yes" plugin_interface="yes" plugin_load="yes" plugin_memory="yes" diff --git a/src/Makefile.am b/src/Makefile.am index fe4af774..d68d0360 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -193,6 +193,10 @@ endif if BUILD_WITH_LIBIOKIT disk_la_LDFLAGS += -lIOKit endif +if BUILD_WITH_LIBSTATGRAB +disk_la_CFLAGS = $(BUILD_WITH_LIBSTATGRAB_CFLAGS) +disk_la_LIBADD = $(BUILD_WITH_LIBSTATGRAB_LDFLAGS) +endif collectd_LDADD += "-dlopen" disk.la collectd_DEPENDENCIES += disk.la endif diff --git a/src/disk.c b/src/disk.c index 5491dcbd..e2ae14e1 100644 --- a/src/disk.c +++ b/src/disk.c @@ -59,6 +59,10 @@ # define UINT_MAX 4294967295U #endif +#if HAVE_STATGRAB_H +# include +#endif + #if HAVE_IOKIT_IOKITLIB_H static mach_port_t io_master_port = MACH_PORT_NULL; /* #endif HAVE_IOKIT_IOKITLIB_H */ @@ -98,6 +102,9 @@ static kstat_t *ksp[MAX_NUMDISK]; static int numdisk = 0; /* #endif HAVE_LIBKSTAT */ +#elif defined(HAVE_LIBSTATGRAB) +/* #endif HAVE_LIBKSTATGRAB */ + #else # error "No applicable input method." #endif @@ -659,7 +666,23 @@ static int disk_read (void) kio.KIO_ROPS, kio.KIO_WOPS); } } -#endif /* defined(HAVE_LIBKSTAT) */ +/* #endif defined(HAVE_LIBKSTAT) */ + +#elif defined(HAVE_LIBSTATGRAB) + sg_disk_io_stats *ds; + int disks, counter; + char name[16]; + + if ((ds = sg_get_disk_io_stats(&disks)) == NULL) + return (0); + + for (counter=0; counter < disks; counter++) { + strncpy(name, ds->disk_name, sizeof(name)); + name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ + disk_submit (name, "disk_octets", ds->read_bytes, ds->write_bytes); + ds++; + } +#endif /* defined(HAVE_LIBSTATGRAB) */ return (0); } /* int disk_read */ -- 2.30.2