X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fswap.c;h=1cf707797f1057b4fb6124c763a46e057b2753ee;hb=89783745dc59079eab34e0c52de6e5e972f50eb2;hp=945c7580aef84dfdc944a0dd8f2e268773159d2a;hpb=838af4cdc6c8674ed3e14a95fea172118c707a85;p=collectd.git diff --git a/src/swap.c b/src/swap.c index 945c7580..1cf70779 100644 --- a/src/swap.c +++ b/src/swap.c @@ -36,26 +36,9 @@ # include #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) @@ -156,7 +143,9 @@ static int swap_read (void) if ((fh = fopen ("/proc/meminfo", "r")) == NULL) { - WARNING ("memory: fopen: %s", strerror (errno)); + char errbuf[1024]; + WARNING ("memory: fopen: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } @@ -182,7 +171,11 @@ static int swap_read (void) } if (fclose (fh)) - WARNING ("memory: fclose: %s", strerror (errno)); + { + char errbuf[1024]; + WARNING ("memory: fclose: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } if ((swap_total == 0LL) || ((swap_free + swap_cached) > swap_total)) return (-1); @@ -203,8 +196,9 @@ static int swap_read (void) if (swapctl (SC_AINFO, &ai) == -1) { + char errbuf[1024]; ERROR ("swap plugin: swapctl failed: %s", - strerror (errno)); + sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } @@ -238,7 +232,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) @@ -303,14 +297,9 @@ static int swap_read (void) return (0); } /* int swap_read */ -#endif /* SWAP_HAVE_READ */ void module_register (void) { - plugin_register_data_set (&data_set); - -#if SWAP_HAVE_READ plugin_register_init ("swap", swap_init); plugin_register_read ("swap", swap_read); -#endif /* SWAP_HAVE_READ */ -} +} /* void module_register */