X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=inline;f=src%2Fswap.c;h=de9b5f3de430ef08fa034df37aae168a9e0f1057;hb=acd25837217277ae9f7dfb68468a626ca10eebd6;hp=24289abd2cbd93612921e82d828dedd46ba19604;hpb=b721e0781d022671b62b15c2407780055c1e5146;p=collectd.git diff --git a/src/swap.c b/src/swap.c index 24289abd..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 @@ -298,9 +311,9 @@ 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_num; i++) @@ -308,8 +321,18 @@ static int swap_read (void) 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);