X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fswap.c;h=de9b5f3de430ef08fa034df37aae168a9e0f1057;hb=daa4b5ab990fac569e684ab8850792bec0a19159;hp=425742e9ef24f33749503aa9a953976cc897d4d6;hpb=b10e5d81780306200ecadaf86605cef5ad8c9a04;p=collectd.git diff --git a/src/swap.c b/src/swap.c index 425742e9..de9b5f3d 100644 --- a/src/swap.c +++ b/src/swap.c @@ -19,6 +19,16 @@ * Florian octo Forster **/ +#if HAVE_CONFIG_H +# include "config.h" +# undef HAVE_CONFIG_H +#endif +/* avoid swap.h error "Cannot use swapctl in the large files compilation environment" */ +#if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64 +# undef _FILE_OFFSET_BITS +# undef _LARGEFILE64_SOURCE +#endif + #include "collectd.h" #include "common.h" #include "plugin.h" @@ -26,6 +36,9 @@ #if HAVE_SYS_SWAP_H # include #endif +#if HAVE_VM_ANON_H +# include +#endif #if HAVE_SYS_PARAM_H # include #endif @@ -289,7 +302,7 @@ static int swap_read (void) } status = swapctl (SWAP_STATS, swap_entries, swap_num); - if (status != swap_entries) + if (status != swap_num) { ERROR ("swap plugin: swapctl (SWAP_STATS) failed with status %i.", status); @@ -298,18 +311,28 @@ static int swap_read (void) } #if defined(DEV_BSIZE) && (DEV_BSIZE > 0) -# define C_SWAP_BLOCK_SIZE DEV_BSIZE +# define C_SWAP_BLOCK_SIZE ((uint64_t) DEV_BSIZE) #else -# define C_SWAP_BLOCK_SIZE 512 +# define C_SWAP_BLOCK_SIZE ((uint64_t) 512) #endif - for (i = 0; i < swap_entries; i++) + for (i = 0; i < swap_num; i++) { if ((swap_entries[i].se_flags & SWF_ENABLE) == 0) continue; - used = swap_entries[i].se_inuse * C_SWAP_BLOCK_SIZE; - total = swap_entries[i].se_nblks * C_SWAP_BLOCK_SIZE; + used += ((uint64_t) swap_entries[i].se_inuse) + * C_SWAP_BLOCK_SIZE; + total += ((uint64_t) swap_entries[i].se_nblks) + * C_SWAP_BLOCK_SIZE; + } + + if (total < used) + { + ERROR ("swap plugin: Total swap space (%"PRIu64") " + "is less than used swap space (%"PRIu64").", + total, used); + return (-1); } swap_submit ("used", (gauge_t) used);