unixsock plugin: Remove the socket-file after closing the socket.
[collectd.git] / src / disk.c
index 36d7b4f..31c3ec2 100644 (file)
 # 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;
@@ -126,7 +80,6 @@ typedef struct diskstats
 } diskstats_t;
 
 static diskstats_t *disklist;
-static int min_poll_count;
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_LIBKSTAT
@@ -159,17 +112,7 @@ static int disk_init (void)
 /* #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);
-       DEBUG ("min_poll_count = %i;", min_poll_count);
+       /* do nothing */
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_LIBKSTAT
@@ -537,10 +480,10 @@ static int disk_read (void)
 
                /* 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)
                {
-                       DEBUG ("(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;
                }
 
@@ -570,6 +513,23 @@ static int disk_read (void)
 /* #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;
 
@@ -583,15 +543,20 @@ static int disk_read (void)
 
                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) */
@@ -602,13 +567,8 @@ static int disk_read (void)
 
 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 */