projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
utils_mount.c: check for null before dereferencing
[collectd.git]
/
src
/
swap.c
diff --git
a/src/swap.c
b/src/swap.c
index
c7b634b
..
fb50cf3
100644
(file)
--- a/
src/swap.c
+++ b/
src/swap.c
@@
-160,6
+160,8
@@
static int swap_init (void) /* {{{ */
/* #endif defined(VM_SWAPUSAGE) */
#elif HAVE_LIBKVM_GETSWAPINFO
/* #endif defined(VM_SWAPUSAGE) */
#elif HAVE_LIBKVM_GETSWAPINFO
+ char errbuf[_POSIX2_LINE_MAX];
+
if (kvm_obj != NULL)
{
kvm_close (kvm_obj);
if (kvm_obj != NULL)
{
kvm_close (kvm_obj);
@@
-168,14
+170,11
@@
static int swap_init (void) /* {{{ */
kvm_pagesize = getpagesize ();
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_open
files failed, %s", errbuf
);
return (-1);
}
/* #endif HAVE_LIBKVM_GETSWAPINFO */
return (-1);
}
/* #endif HAVE_LIBKVM_GETSWAPINFO */
@@
-221,7
+220,7
@@
static void swap_submit_gauge (const char *plugin_instance, /* {{{ */
swap_submit (plugin_instance, "swap", type_instance, v);
} /* }}} void swap_submit_gauge */
swap_submit (plugin_instance, "swap", type_instance, v);
} /* }}} void swap_submit_gauge */
-#if KERNEL_LINUX
+#if KERNEL_LINUX
|| HAVE_PERFSTAT
static void swap_submit_derive (const char *plugin_instance, /* {{{ */
const char *type_instance, derive_t value)
{
static void swap_submit_derive (const char *plugin_instance, /* {{{ */
const char *type_instance, derive_t value)
{
@@
-230,7
+229,9
@@
static void swap_submit_derive (const char *plugin_instance, /* {{{ */
v.derive = value;
swap_submit (plugin_instance, "swap_io", type_instance, v);
} /* }}} void swap_submit_derive */
v.derive = value;
swap_submit (plugin_instance, "swap_io", type_instance, v);
} /* }}} void swap_submit_derive */
+#endif
+#if KERNEL_LINUX
static int swap_read_separate (void) /* {{{ */
{
FILE *fh;
static int swap_read_separate (void) /* {{{ */
{
FILE *fh;
@@
-337,7
+338,7
@@
static int swap_read_combined (void) /* {{{ */
fclose (fh);
fclose (fh);
- if (
have_data != 0x07
)
+ if (
(have_data & 0x03) != 0x03
)
return (ENOENT);
if (isnan (swap_total)
return (ENOENT);
if (isnan (swap_total)
@@
-349,7
+350,8
@@
static int swap_read_combined (void) /* {{{ */
swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
- swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
+ if (have_data & 0x04)
+ swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
return (0);
} /* }}} int swap_read_combined */
return (0);
} /* }}} int swap_read_combined */
@@
-786,8
+788,12
@@
static int swap_read (void) /* {{{ */
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
+
swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
+ swap_submit_gauge (NULL, "reserved", (gauge_t) pmemory.pgsp_rsvd * pagesize);
+ swap_submit_derive (NULL, "in", (derive_t) pmemory.pgspins * pagesize);
+ swap_submit_derive (NULL, "out", (derive_t) pmemory.pgspouts * pagesize);
return (0);
} /* }}} int swap_read */
return (0);
} /* }}} int swap_read */