Added "type" to the value_list_t struct.
[collectd.git] / src / swap.c
index 86bdc35..632d372 100644 (file)
 #  include <kvm.h>
 #endif
 
-#if KERNEL_LINUX || HAVE_LIBKSTAT || defined(VM_SWAPUSAGE) || HAVE_LIBKVM || HAVE_LIBSTATGRAB
-# define SWAP_HAVE_READ 1
-#else
-# define SWAP_HAVE_READ 0
-#endif
-
 #undef  MAX
 #define MAX(x,y) ((x) > (y) ? (x) : (y))
 
-static data_source_t data_source[1] =
-{
-       {"value", DS_TYPE_GAUGE, 0, 1099511627776.0}
-};
-
-static data_set_t data_set =
-{
-       "swap", 1, data_source
-};
-
-#if SWAP_HAVE_READ
 #if KERNEL_LINUX
 /* No global variables */
 /* #endif KERNEL_LINUX */
@@ -76,6 +59,10 @@ int kvm_pagesize;
 
 #elif HAVE_LIBSTATGRAB
 /* No global variables */
+/* #endif HAVE_LIBSTATGRAB */
+
+#else
+# error "No applicable input method."
 #endif /* HAVE_LIBSTATGRAB */
 
 static int swap_init (void)
@@ -135,9 +122,10 @@ static void swap_submit (const char *type_instance, double value)
        vl.time = time (NULL);
        strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "swap");
+       strcpy (vl.type, "swap");
        strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
-       plugin_dispatch_values ("swap", &vl);
+       plugin_dispatch_values (&vl);
 } /* void swap_submit */
 
 static int swap_read (void)
@@ -245,7 +233,7 @@ static int swap_read (void)
 
        swap_submit ("used", swap_alloc);
        swap_submit ("free", swap_avail);
-       swap_submit ("reserved", swap_resv - swap_alloc);
+       swap_submit ("reserved", swap_resv);
 /* #endif HAVE_LIBKSTAT */
 
 #elif defined(VM_SWAPUSAGE)
@@ -310,18 +298,9 @@ static int swap_read (void)
 
        return (0);
 } /* int swap_read */
-#endif /* SWAP_HAVE_READ */
 
-void module_register (modreg_e load)
+void module_register (void)
 {
-       if (load & MR_DATASETS)
-               plugin_register_data_set (&data_set);
-
-#if SWAP_HAVE_READ
-       if (load & MR_READ)
-       {
-               plugin_register_init ("swap", swap_init);
-               plugin_register_read ("swap", swap_read);
-       }
-#endif /* SWAP_HAVE_READ */
+       plugin_register_init ("swap", swap_init);
+       plugin_register_read ("swap", swap_read);
 } /* void module_register */