+ this_total = ((derive_t) s->swt_ent[i].ste_pages) * pagesize;
+ this_avail = ((derive_t) s->swt_ent[i].ste_free) * pagesize;
+
+ /* Shortcut for the "combined" setting (default) */
+ if (!report_by_device)
+ {
+ avail += this_avail;
+ total += this_total;
+ continue;
+ }
+
+ /* Okay, using "/" as swap device would be super-weird, but
+ * we'll handle it anyway to cover all cases. */
+ if (strcmp ("/", s->swt_ent[i].ste_path) == 0)
+ sstrncpy (path, "root", sizeof (path));
+ else
+ {
+ int j;
+
+ s->swt_ent[i].ste_path[PATH_MAX - 1] = 0;
+ /* Don't copy the leading slash */
+ sstrncpy (path, &s->swt_ent[i].ste_path[1], sizeof (path));
+ /* Convert slashes to dashes, just like the "df" plugin. */
+ for (j = 0; path[j] != 0; j++)
+ if (path[j] == '/')
+ path[j] = '-';
+ }
+
+ swap_submit_inst (path, "used", this_total - this_avail, DS_TYPE_GAUGE);
+ swap_submit_inst (path, "free", this_avail, DS_TYPE_GAUGE);
+ } /* for (swap_num) */