#include "collectd.h"
#include "common.h"
#include "plugin.h"
-#include "utils_debug.h"
#if HAVE_MACH_MACH_TYPES_H
# include <mach/mach_types.h>
# define DISK_HAVE_READ 0
#endif
-/* 2^34 = 17179869184 = ~17.2GByte/s */
-static data_source_t octets_dsrc[2] =
-{
- {"read", DS_TYPE_COUNTER, 0, 17179869183.0},
- {"write", DS_TYPE_COUNTER, 0, 17179869183.0}
-};
-
-static data_set_t octets_ds =
-{
- "disk_octets", 2, octets_dsrc
-};
-
-static data_source_t operations_dsrc[2] =
-{
- {"read", DS_TYPE_COUNTER, 0, 4294967295.0},
- {"write", DS_TYPE_COUNTER, 0, 4294967295.0}
-};
-
-static data_set_t operations_ds =
-{
- "disk_ops", 2, operations_dsrc
-};
-
-static data_source_t merged_dsrc[2] =
-{
- {"read", DS_TYPE_COUNTER, 0, 4294967295.0},
- {"write", DS_TYPE_COUNTER, 0, 4294967295.0}
-};
-
-static data_set_t merged_ds =
-{
- "disk_merged", 2, merged_dsrc
-};
-
-/* max is 1000000us per second. */
-static data_source_t time_dsrc[2] =
-{
- {"read", DS_TYPE_COUNTER, 0, 1000000.0},
- {"write", DS_TYPE_COUNTER, 0, 1000000.0}
-};
-
-static data_set_t time_ds =
-{
- "disk_time", 2, time_dsrc
-};
-
#if DISK_HAVE_READ
#if HAVE_IOKIT_IOKITLIB_H
static mach_port_t io_master_port = MACH_PORT_NULL;
} diskstats_t;
static diskstats_t *disklist;
-static int min_poll_count;
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
status = IOMasterPort (MACH_PORT_NULL, &io_master_port);
if (status != kIOReturnSuccess)
{
- syslog (LOG_ERR, "IOMasterPort failed: %s",
+ ERROR ("IOMasterPort failed: %s",
mach_error_string (status));
io_master_port = MACH_PORT_NULL;
return (-1);
/* #endif HAVE_IOKIT_IOKITLIB_H */
#elif KERNEL_LINUX
- 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);
+ /* do nothing */
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
kCFStringEncodingASCII);
if (key_obj == NULL)
{
- DBG ("CFStringCreateWithCString (%s) failed.", key);
+ DEBUG ("CFStringCreateWithCString (%s) failed.", key);
return (-1LL);
}
if (val_obj == NULL)
{
- DBG ("CFDictionaryGetValue (%s) failed.", key);
+ DEBUG ("CFDictionaryGetValue (%s) failed.", key);
return (-1LL);
}
if (!CFNumberGetValue (val_obj, kCFNumberSInt64Type, &val_int))
{
- DBG ("CFNumberGetValue (%s) failed.", key);
+ DEBUG ("CFNumberGetValue (%s) failed.", key);
return (-1LL);
}
!= kIOReturnSuccess)
{
/* This fails for example for DVD/CD drives.. */
- DBG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
+ DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
IOObjectRelease (disk);
continue;
}
kNilOptions)
!= kIOReturnSuccess)
{
- syslog (LOG_ERR, "disk-plugin: IORegistryEntryCreateCFProperties failed.");
+ ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
IOObjectRelease (disk_child);
IOObjectRelease (disk);
continue;
if (props_dict == NULL)
{
- DBG ("IORegistryEntryCreateCFProperties (disk) failed.");
+ DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
IOObjectRelease (disk_child);
IOObjectRelease (disk);
continue;
if (stats_dict == NULL)
{
- DBG ("CFDictionaryGetValue (%s) failed.",
+ DEBUG ("CFDictionaryGetValue (%s) failed.",
kIOBlockStorageDriverStatisticsKey);
CFRelease (props_dict);
IOObjectRelease (disk_child);
kNilOptions)
!= kIOReturnSuccess)
{
- DBG ("IORegistryEntryCreateCFProperties (disk_child) failed.");
+ DEBUG ("IORegistryEntryCreateCFProperties (disk_child) failed.");
IOObjectRelease (disk_child);
CFRelease (props_dict);
IOObjectRelease (disk);
if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64)
{
- DBG ("snprintf (major, minor) failed.");
+ DEBUG ("snprintf (major, minor) failed.");
CFRelease (child_dict);
IOObjectRelease (disk_child);
CFRelease (props_dict);
IOObjectRelease (disk);
continue;
}
- DBG ("disk_name = %s", disk_name);
+ DEBUG ("disk_name = %s", disk_name);
if ((read_byt != -1LL) || (write_byt != -1LL))
disk_submit (disk_name, "disk_octets", read_byt, write_byt);
}
else
{
- DBG ("numfields = %i; => unknown file format.", numfields);
+ DEBUG ("numfields = %i; => unknown file format.", numfields);
continue;
}
/* Don't write to the RRDs if we've just started.. */
ds->poll_count++;
- if (ds->poll_count <= min_poll_count)
+ if (ds->poll_count <= 2)
{
- DBG ("(ds->poll_count = %i) <= (min_poll_count = %i); => Not writing.",
- ds->poll_count, min_poll_count);
+ DEBUG ("(ds->poll_count = %i) <= (min_poll_count = 2); => Not writing.",
+ ds->poll_count);
continue;
}
if ((read_count == 0) && (write_count == 0))
{
- DBG ("((read_count == 0) && (write_count == 0)); => Not writing.");
+ DEBUG ("((read_count == 0) && (write_count == 0)); => Not writing.");
continue;
}
/* #endif defined(KERNEL_LINUX) */
#elif HAVE_LIBKSTAT
+# if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME
+# define KIO_ROCTETS reads
+# define KIO_WOCTETS writes
+# define KIO_ROPS nreads
+# define KIO_WOPS nwrites
+# define KIO_RTIME rtime
+# define KIO_WTIME wtime
+# elif HAVE_KSTAT_IO_T_NWRITTEN && HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_WTIME
+# define KIO_ROCTETS nread
+# define KIO_WOCTETS nwritten
+# define KIO_ROPS reads
+# define KIO_WOPS writes
+# define KIO_RTIME rtime
+# define KIO_WTIME wtime
+# else
+# error "kstat_io_t does not have the required members"
+# endif
static kstat_io_t kio;
int i;
if (strncmp (ksp[i]->ks_class, "disk", 4) == 0)
{
- disk_submit (ksp[i]->ks_name, "disk_octets", kio.reads, kio.writes);
- disk_submit (ksp[i]->ks_name, "disk_ops", kio.nreads, kio.nwrites);
+ disk_submit (ksp[i]->ks_name, "disk_octets",
+ kio.KIO_ROCTETS, kio.KIO_WOCTETS);
+ disk_submit (ksp[i]->ks_name, "disk_ops",
+ kio.KIO_ROPS, kio.KIO_WOPS);
/* FIXME: Convert this to microseconds if necessary */
- disk_submit (ksp[i]->ks_name, "disk_time", kio.rtime, kio.wtime);
+ disk_submit (ksp[i]->ks_name, "disk_time",
+ kio.KIO_RTIME, kio.KIO_WTIME);
}
else if (strncmp (ksp[i]->ks_class, "partition", 9) == 0)
{
- disk_submit (ksp[i]->ks_name, "disk_octets", kio.reads, kio.writes);
- disk_submit (ksp[i]->ks_name, "disk_ops", kio.nreads, kio.nwrites);
+ disk_submit (ksp[i]->ks_name, "disk_octets",
+ kio.KIO_ROCTETS, kio.KIO_WOCTETS);
+ disk_submit (ksp[i]->ks_name, "disk_ops",
+ kio.KIO_ROPS, kio.KIO_WOPS);
}
}
#endif /* defined(HAVE_LIBKSTAT) */
void module_register (void)
{
- plugin_register_data_set (&octets_ds);
- plugin_register_data_set (&operations_ds);
- plugin_register_data_set (&merged_ds);
- plugin_register_data_set (&time_ds);
-
#if DISK_HAVE_READ
plugin_register_init ("disk", disk_init);
plugin_register_read ("disk", disk_read);
#endif /* DISK_HAVE_READ */
-}
+} /* void module_register */