X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fswap.c;h=2e0939d16dc938027df9d058b99a87051a1f3089;hb=4e89060ceb1a14ec7f9abfe9caa6b0da7e76bd5c;hp=746ba51a110c594275393f04e72d6f7198673c80;hpb=867ad628dc6fcd05bd584b605d7093cfc00c3d07;p=collectd.git diff --git a/src/swap.c b/src/swap.c index 746ba51a..2e0939d1 100644 --- a/src/swap.c +++ b/src/swap.c @@ -74,14 +74,14 @@ #if KERNEL_LINUX #define SWAP_HAVE_REPORT_BY_DEVICE 1 static derive_t pagesize; -static _Bool report_bytes = 0; -static _Bool report_by_device = 0; +static bool report_bytes; +static bool report_by_device; /* #endif KERNEL_LINUX */ #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS #define SWAP_HAVE_REPORT_BY_DEVICE 1 static derive_t pagesize; -static _Bool report_by_device = 0; +static bool report_by_device; /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */ #elif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS @@ -109,8 +109,9 @@ static int pagesize; #error "No applicable input method." #endif /* HAVE_LIBSTATGRAB */ -static _Bool values_absolute = 1; -static _Bool values_percentage = 0; +static bool values_absolute = true; +static bool values_percentage; +static bool report_io = true; static int swap_config(oconfig_item_t *ci) /* {{{ */ { @@ -136,6 +137,8 @@ static int swap_config(oconfig_item_t *ci) /* {{{ */ cf_util_get_boolean(child, &values_absolute); else if (strcasecmp("ValuesPercentage", child->key) == 0) cf_util_get_boolean(child, &values_percentage); + else if (strcasecmp("ReportIO", child->key) == 0) + cf_util_get_boolean(child, &report_io); else WARNING("swap plugin: Unknown config option: \"%s\"", child->key); } @@ -231,9 +234,7 @@ static int swap_read_separate(void) /* {{{ */ fh = fopen("/proc/swaps", "r"); if (fh == NULL) { - char errbuf[1024]; - WARNING("swap plugin: fopen (/proc/swaps) failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("swap plugin: fopen (/proc/swaps) failed: %s", STRERRNO); return -1; } @@ -288,9 +289,7 @@ static int swap_read_combined(void) /* {{{ */ fh = fopen("/proc/meminfo", "r"); if (fh == NULL) { - char errbuf[1024]; - WARNING("swap plugin: fopen (/proc/meminfo) failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("swap plugin: fopen (/proc/meminfo) failed: %s", STRERRNO); return -1; } @@ -336,7 +335,7 @@ static int swap_read_io(void) /* {{{ */ FILE *fh; char buffer[1024]; - _Bool old_kernel = 0; + bool old_kernel = 0; uint8_t have_data = 0; derive_t swap_in = 0; @@ -347,8 +346,7 @@ static int swap_read_io(void) /* {{{ */ /* /proc/vmstat does not exist in kernels <2.6 */ fh = fopen("/proc/stat", "r"); if (fh == NULL) { - char errbuf[1024]; - WARNING("swap: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("swap: fopen: %s", STRERRNO); return -1; } else old_kernel = 1; @@ -406,11 +404,12 @@ static int swap_read(void) /* {{{ */ else swap_read_combined(); - swap_read_io(); + if (report_io) + swap_read_io(); return 0; } /* }}} int swap_read */ - /* #endif KERNEL_LINUX */ +/* #endif KERNEL_LINUX */ /* * Under Solaris, two mechanisms can be used to read swap statistics, swapctl @@ -432,9 +431,7 @@ static int swap_read_kstat(void) /* {{{ */ struct anoninfo ai; if (swapctl(SC_AINFO, &ai) == -1) { - char errbuf[1024]; - ERROR("swap plugin: swapctl failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("swap plugin: swapctl failed: %s", STRERRNO); return -1; } @@ -509,9 +506,7 @@ static int swap_read(void) /* {{{ */ status = swapctl(SC_LIST, s); if (status < 0) { - char errbuf[1024]; - ERROR("swap plugin: swapctl (SC_LIST) failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("swap plugin: swapctl (SC_LIST) failed: %s", STRERRNO); sfree(s_paths); sfree(s); return -1; @@ -715,9 +710,7 @@ static int swap_read(void) /* {{{ */ status = perfstat_memory_total(NULL, &pmemory, sizeof(perfstat_memory_total_t), 1); if (status < 0) { - char errbuf[1024]; - WARNING("swap plugin: perfstat_memory_total failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("swap plugin: perfstat_memory_total failed: %s", STRERRNO); return -1; } @@ -726,8 +719,11 @@ static int swap_read(void) /* {{{ */ reserved = (gauge_t)(pmemory.pgsp_rsvd * pagesize); swap_submit_usage(NULL, total - free, free, "reserved", reserved); - swap_submit_derive("in", (derive_t)pmemory.pgspins * pagesize); - swap_submit_derive("out", (derive_t)pmemory.pgspouts * pagesize); + + if (report_io) { + swap_submit_derive("in", (derive_t)pmemory.pgspins * pagesize); + swap_submit_derive("out", (derive_t)pmemory.pgspouts * pagesize); + } return 0; } /* }}} int swap_read */