summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c35203c)
raw | patch | inline | side by side (parent: c35203c)
author | Stefan Völkel <bd@bc-bd.org> | |
Mon, 17 Aug 2009 13:50:17 +0000 (13:50 +0000) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 19 Aug 2009 09:42:49 +0000 (11:42 +0200) |
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/swap.c | patch | blob | history | |
src/types.db | patch | blob | history |
diff --git a/src/swap.c b/src/swap.c
index de9b5f3de430ef08fa034df37aae168a9e0f1057..dccea6d0cc039e0c18ff06d96b963e24ee8db938 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
return (0);
}
-static void swap_submit (const char *type_instance, double value)
+static void swap_submit (const char *type_instance, derive_t value, unsigned type)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- values[0].gauge = value;
+ switch (type)
+ {
+ case DS_TYPE_GAUGE:
+ values[0].gauge = value;
+ sstrncpy (vl.type, "swap", sizeof (vl.type));
+ break;
+ case DS_TYPE_DERIVE:
+ values[0].derive = value;
+ sstrncpy (vl.type, "swap_io", sizeof (vl.type));
+ break;
+ default:
+ ERROR ("swap plugin: swap_submit called with wrong"
+ " type");
+ }
vl.values = values;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "swap", sizeof (vl.plugin));
- sstrncpy (vl.type, "swap", sizeof (vl.type));
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
unsigned long long swap_cached = 0LL;
unsigned long long swap_free = 0LL;
unsigned long long swap_total = 0LL;
+ unsigned long long swap_in = 0LL;
+ unsigned long long swap_out = 0LL;
if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
{
swap_used = swap_total - (swap_free + swap_cached);
- swap_submit ("used", swap_used);
- swap_submit ("free", swap_free);
- swap_submit ("cached", swap_cached);
+ if ((fh = fopen ("/proc/vmstat", "r")) == NULL)
+ {
+ char errbuf[1024];
+ WARNING ("swap: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+
+ while (fgets (buffer, 1024, fh) != NULL)
+ {
+ unsigned long long *val = NULL;
+
+ if (strncasecmp (buffer, "pswpin", 6) == 0)
+ val = &swap_in;
+ else if (strncasecmp (buffer, "pswpout", 7) == 0)
+ val = &swap_out;
+ else
+ continue;
+
+ numfields = strsplit (buffer, fields, 8);
+
+ if (numfields < 2)
+ continue;
+
+ *val = atoll (fields[1]);
+ }
+
+ if (fclose (fh))
+ {
+ char errbuf[1024];
+ WARNING ("swap: fclose: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
+
+ swap_submit ("used", swap_used, DS_TYPE_GAUGE);
+ swap_submit ("free", swap_free, DS_TYPE_GAUGE);
+ swap_submit ("cached", swap_cached, DS_TYPE_GAUGE);
+ swap_submit ("in", swap_in, DS_TYPE_DERIVE);
+ swap_submit ("out", swap_out, DS_TYPE_DERIVE);
+
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
diff --git a/src/types.db b/src/types.db
index ec92f4b40ab90c997feab1b52812af1ae2a5faa4..dd37cc13905f1e63d6a3a072dbbf5c73f96c48c6 100644 (file)
--- a/src/types.db
+++ b/src/types.db
spam_check value:GAUGE:0:U
spam_score value:GAUGE:U:U
swap value:GAUGE:0:1099511627776
+swap_io value:DERIVE:0:1099511627776
tcp_connections value:GAUGE:0:4294967295
temperature value:GAUGE:-273.15:U
time_dispersion seconds:GAUGE:-1000000:1000000