summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dc0b5c7)
raw | patch | inline | side by side (parent: dc0b5c7)
author | Florian Forster <octo@collectd.org> | |
Wed, 12 Sep 2012 16:55:08 +0000 (18:55 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 12 Sep 2012 19:26:27 +0000 (21:26 +0200) |
When enabled, swap I/O is reported in bytes, not pages. Only valid for Linux.
This should fix Github issue #10.
This should fix Github issue #10.
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/swap.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 21d0eb177d42a8ec2f4b7a47a7e1d031aa41e8eb..e508be7b7395a8fc3558d3e38ba8ad6356ab5676 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# </Host>
#</Plugin>
+#<Plugin "swap">
+# ReportBytes true
+#</Plugin>
+
#<Plugin "table">
# <Table "/proc/slabinfo">
# Instance "slabinfo"
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 75f79429630e7c7b49c23ec4765a9412b1f9cbd4..f359e9a08cca8e5806490b4a44a252f3d8b52431 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -4031,6 +4031,23 @@ Since the configuration of the C<snmp plugin> is a little more complicated than
other plugins, its documentation has been moved to an own manpage,
L<collectd-snmp(5)>. Please see there for details.
+=head2 Plugin C<swap>
+
+The C<swap plugin> reports the number of bytes currently swapped out and the
+amount of swap space available. The precise metrics being exported depends on
+your operating system.
+
+Options:
+
+=over 4
+
+=item B<ReportBytes> B<false>|B<true>
+
+When enabled, the I<swap I/O> is reported in bytes. When disabled, the default,
+I<swap I/O> is reported in pages. This option is available under Linux only.
+
+=back
+
=head2 Plugin C<syslog>
=over 4
diff --git a/src/swap.c b/src/swap.c
index 46ba6652953726ce0b7d90aecea2345f681ec64b..1a152c9069c4eff54dcbb23d2918da286f0abea5 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
/**
* collectd - src/swap.c
- * Copyright (C) 2005-2009 Florian octo Forster
+ * Copyright (C) 2005-2012 Florian octo Forster
* Copyright (C) 2009 Stefan Völkel
* Copyright (C) 2009 Manuel Sanmartin
*
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#if KERNEL_LINUX
-/* No global variables */
+static derive_t pagesize;
+static _Bool report_bytes = 0;
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
# error "No applicable input method."
#endif /* HAVE_LIBSTATGRAB */
+static const char *config_keys[] =
+{
+ "ReportBytes"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
static int swap_init (void)
{
#if KERNEL_LINUX
- /* No init stuff */
+ pagesize = (derive_t) sysconf (_SC_PAGESIZE);
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
sstrerror (errno, errbuf, sizeof (errbuf)));
}
+ if (report_bytes)
+ {
+ swap_in *= pagesize;
+ swap_out *= pagesize;
+ }
+
swap_submit ("used", 1024 * swap_used, DS_TYPE_GAUGE);
swap_submit ("free", 1024 * swap_free, DS_TYPE_GAUGE);
swap_submit ("cached", 1024 * swap_cached, DS_TYPE_GAUGE);
return (0);
} /* int swap_read */
+static int swap_config (const char *key, const char *value)
+{
+ if (strcasecmp ("ReportBytes", key) == 0)
+ {
+#if KERNEL_LINUX
+ report_bytes = IS_TRUE (value) ? 1 : 0;
+#else
+ WARNING ("swap plugin: The \"ReportBytes\" option is only "
+ "valid under Linux. The option is going to "
+ "be ignored.");
+#endif
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+} /* int swap_config */
+
void module_register (void)
{
+ plugin_register_config ("swap", swap_config,
+ config_keys, config_keys_num);
plugin_register_init ("swap", swap_init);
plugin_register_read ("swap", swap_read);
} /* void module_register */