apcups plugin: Fix the types used in the plugin.
[collectd.git] / src / tape.c
index 2345cb3..5e01f0d 100644 (file)
 # define TAPE_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 =
-{
-       "tape_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 =
-{
-       "tape_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 =
-{
-       "tape_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 =
-{
-       "tape_time", 2, time_dsrc
-};
-
 #if TAPE_HAVE_READ
 #if defined(HAVE_LIBKSTAT)
 #define MAX_NUMTAPE 256
@@ -134,6 +88,23 @@ static int tape_read (void)
 {
 
 #if defined(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;
 
@@ -150,10 +121,13 @@ static int tape_read (void)
 
                if (strncmp (ksp[i]->ks_class, "tape", 4) == 0)
                {
-                       tape_submit (ksp[i]->ks_name, "tape_octets", kio.reads, kio.writes);
-                       tape_submit (ksp[i]->ks_name, "tape_ops", kio.nreads, kio.nwrites);
+                       tape_submit (ksp[i]->ks_name, "tape_octets",
+                                       kio.KIO_ROCTETS, kio.KIO_WOCTETS);
+                       tape_submit (ksp[i]->ks_name, "tape_ops",
+                                       kio.KIO_ROPS, kio.KIO_WOPS);
                        /* FIXME: Convert this to microseconds if necessary */
-                       tape_submit (ksp[i]->ks_name, "tape_time", kio.rtime, kio.wtime);
+                       tape_submit (ksp[i]->ks_name, "tape_time",
+                                       kio.KIO_RTIME, kio.KIO_WTIME);
                }
        }
 #endif /* defined(HAVE_LIBKSTAT) */
@@ -162,21 +136,10 @@ static int tape_read (void)
 }
 #endif /* TAPE_HAVE_READ */
 
-void module_register (modreg_e load)
+void module_register (void)
 {
-       if (load & MR_DATASETS)
-       {
-               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 TAPE_HAVE_READ
-       if (load & MR_READ)
-       {
-               plugin_register_init ("tape", tape_init);
-               plugin_register_read ("tape", tape_read);
-       }
+       plugin_register_init ("tape", tape_init);
+       plugin_register_read ("tape", tape_read);
 #endif /* TAPE_HAVE_READ */
 }