X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fswap.c;h=cfde4ea6d2bd9d194abbab16d4d2269e7347e114;hb=d8a02e6c6f5875dfcab7b011d1f340e3a13c9e39;hp=0642afac78d82792318f40a57696cfe862d13ed2;hpb=b49d4e33978d4c9508b68e931a7a27773f0348e1;p=collectd.git diff --git a/src/swap.c b/src/swap.c index 0642afac..cfde4ea6 100644 --- a/src/swap.c +++ b/src/swap.c @@ -157,6 +157,8 @@ static int swap_init (void) /* {{{ */ /* #endif defined(VM_SWAPUSAGE) */ #elif HAVE_LIBKVM_GETSWAPINFO + char errbuf[_POSIX2_LINE_MAX]; + if (kvm_obj != NULL) { kvm_close (kvm_obj); @@ -165,14 +167,11 @@ static int swap_init (void) /* {{{ */ kvm_pagesize = getpagesize (); - if ((kvm_obj = kvm_open (NULL, /* execfile */ - NULL, /* corefile */ - NULL, /* swapfile */ - O_RDONLY, /* flags */ - NULL)) /* errstr */ - == NULL) + kvm_obj = kvm_openfiles (NULL, "/dev/null", NULL, O_RDONLY, errbuf); + + if (kvm_obj == NULL) { - ERROR ("swap plugin: kvm_open failed."); + ERROR ("swap plugin: kvm_openfiles failed, %s", errbuf); return (-1); } /* #endif HAVE_LIBKVM_GETSWAPINFO */ @@ -205,11 +204,11 @@ static void swap_submit_usage (char const *plugin_instance, /* {{{ */ sstrncpy (vl.type, "swap", sizeof (vl.type)); if (values_absolute) - plugin_dispatch_multivalue (&vl, 0, + plugin_dispatch_multivalue (&vl, 0, DS_TYPE_GAUGE, "used", used, "free", free, other_name, other_value, NULL); if (values_percentage) - plugin_dispatch_multivalue (&vl, 1, + plugin_dispatch_multivalue (&vl, 1, DS_TYPE_GAUGE, "used", used, "free", free, other_name, other_value, NULL); } /* }}} void swap_submit_usage */ @@ -282,7 +281,8 @@ static int swap_read_separate (void) /* {{{ */ if (total < used) continue; - swap_submit_usage (path, used, total - used, NULL, NAN); + swap_submit_usage (path, used * 1024.0, (total - used) * 1024.0, + NULL, NAN); } fclose (fh); @@ -341,8 +341,9 @@ static int swap_read_combined (void) /* {{{ */ if (swap_used < 0.0) return (EINVAL); - swap_submit_usage (NULL, swap_used, swap_free, - isnan (swap_cached) ? NULL : "cached", swap_cached); + swap_submit_usage (NULL, swap_used * 1024.0, swap_free * 1024.0, + isnan (swap_cached) ? NULL : "cached", + isnan (swap_cached) ? NAN : swap_cached * 1024.0); return (0); } /* }}} int swap_read_combined */