- 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)
+ {
+ derive_t *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 = (derive_t) 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);
+