+ fclose(fp);
+
+ return smprintf("%f", (float)(total - free - buffers - cached) / 1024 / 1024);
+}
+
+static char *
+run_command(const char *cmd)
+{
+ FILE *fp;
+ char buf[1024] = "n/a";
+
+ fp = popen(cmd, "r");
+ if (fp == NULL) {
+ warn("Failed to get command output for %s", cmd);
+ return smprintf(UNKNOWN_STR);
+ }
+ fgets(buf, sizeof(buf)-1, fp);
+ pclose(fp);
+
+ buf[strlen(buf)] = '\0';
+ strtok(buf, "\n");
+
+ return smprintf("%s", buf);
+}
+
+static char *
+swap_free(void)
+{
+ long free;
+ FILE *fp;
+ char buf[2048];
+ size_t bytes_read;
+ char *match;
+
+ fp = fopen("/proc/meminfo", "r");
+ if (fp == NULL) {
+ warn("Failed to open file /proc/meminfo");
+ return smprintf(UNKNOWN_STR);
+ }
+ bytes_read = fread(buf, sizeof(char), sizeof(buf), fp);
+ buf[bytes_read] = '\0';
+ fclose(fp);
+ if (bytes_read == 0 || bytes_read == sizeof(buf)) {
+ warn("Failed to read /proc/meminfo\n");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ match = strstr(buf, "SwapFree");
+ sscanf(match, "SwapFree: %ld kB\n", &free);
+
+ return smprintf("%f", (float)free / 1024 / 1024);
+}
+
+static char *
+swap_perc(void)
+{
+ long total, free, cached;
+ FILE *fp;
+ char buf[2048];
+ size_t bytes_read;
+ char *match;