} /* }}} int swap_init */
static void swap_append_usage3(metric_family_t *fams, char const *device,
- gauge_t used, gauge_t free,
+ gauge_t total, gauge_t used, gauge_t free,
char const *other_name, gauge_t other) {
metric_family_t *fam_usage = &fams[FAM_SWAP_USAGE];
metric_family_t *fam_utilization = &fams[FAM_SWAP_UTILIZATION];
}
if (report_utilization) {
- gauge_t total = used + free;
if (have_other) {
- total += other;
-
metric_family_append(fam_utilization, label_state, other_name,
(value_t){.gauge = other / total}, &m);
}
metric_reset(&m);
} /* void swap_append_usage3 */
-static void swap_append_usage(metric_family_t *fams, char *device, gauge_t used,
- gauge_t free) {
- swap_append_usage3(fams, device, used, free, NULL, NAN);
+static void swap_append_usage(metric_family_t *fams, char *device,
+ gauge_t total, gauge_t used, gauge_t free) {
+ swap_append_usage3(fams, device, total, used, free, NULL, NAN);
}
#if KERNEL_LINUX || HAVE_PERFSTAT || KERNEL_NETBSD
if (total < used)
continue;
- swap_append_usage(fams, path, used * 1024.0, (total - used) * 1024.0);
+ swap_append_usage(fams, path, total * 1024.0, used * 1024.0,
+ (total - used) * 1024.0);
}
fclose(fh);
if (swap_used < 0.0)
return EINVAL;
- swap_append_usage3(fams, NULL, swap_used * 1024.0, swap_free * 1024.0,
- "cached", swap_cached * 1024.0);
+ swap_append_usage3(fams, NULL, swap_total * 1024.0, swap_used * 1024.0,
+ swap_free * 1024.0, "cached", swap_cached * 1024.0);
return 0;
} /* }}} int swap_read_combined */
swap_resv = (gauge_t)((ai.ani_resv + ai.ani_free - ai.ani_max) * pagesize);
swap_avail = (gauge_t)((ai.ani_max - ai.ani_resv) * pagesize);
- swap_append_usage3(fams, NULL, swap_alloc, swap_avail, "reserved", swap_resv);
+ swap_append_usage3(fams, NULL, (swap_alloc + swap_resv + swap_avail),
+ swap_alloc, swap_avail, "reserved", swap_resv);
return 0;
} /* }}} int swap_read_kstat */
sstrncpy(path, s->swt_ent[i].ste_path, sizeof(path));
- swap_append_usage(fams, path, this_total - this_avail, this_avail);
+ swap_append_usage(fams, path, this_total, this_total - this_avail,
+ this_avail);
} /* for (swap_num) */
if (total < avail) {
/* If the "separate" option was specified (report_by_device == true) all
* values have already been dispatched from within the loop. */
if (!report_by_device) {
- swap_append_usage(fams, NULL, total - avail, avail);
+ swap_append_usage(fams, NULL, total, total - avail, avail);
}
sfree(s_paths);
sstrncpy(path, swap_entries[i].se_path, sizeof(path));
- swap_append_usage(fams, path, this_used, this_total - this_used);
+ swap_append_usage(fams, path, this_total, this_used,
+ this_total - this_used);
} /* for (swap_num) */
if (total < used) {
/* If the "separate" option was specified (report_by_device == 1), all
* values have already been dispatched from within the loop. */
if (!report_by_device) {
- swap_append_usage(fams, NULL, used, total - used);
+ swap_append_usage(fams, NULL, total, used, total - used);
}
sfree(swap_entries);
return -1;
/* The returned values are bytes. */
- swap_append_usage(fams, NULL, (gauge_t)sw_usage.xsu_used,
- (gauge_t)sw_usage.xsu_avail);
+ swap_append_usage(fams, NULL, (gauge_t)sw_usage.xsu_total,
+ (gauge_t)sw_usage.xsu_used, (gauge_t)sw_usage.xsu_avail);
return 0;
} /* }}} int swap_read_fam */
total *= (gauge_t)kvm_pagesize;
used *= (gauge_t)kvm_pagesize;
- swap_append_usage(fams, NULL, used, total - used);
+ swap_append_usage(fams, NULL, total, used, total - used);
return 0;
} /* }}} int swap_read_fam */
if (swap == NULL)
return -1;
- swap_append_usage(fams, NULL, (gauge_t)swap->used, (gauge_t)swap->free);
+ swap_append_usage(fams, NULL, (gauge_t)swap->total, (gauge_t)swap->used,
+ (gauge_t)swap->free);
return 0;
} /* }}} int swap_read_fam */
gauge_t free = (gauge_t)(pmemory.pgsp_free * pagesize);
gauge_t reserved = (gauge_t)(pmemory.pgsp_rsvd * pagesize);
- swap_append_usage3(fams, NULL, total - free, free, "reserved", reserved);
+ swap_append_usage3(fams, NULL, total, total - free, free, "reserved",
+ reserved);
counter_t swap_in = pmemory.pgspins;
counter_t swap_out = pmemory.pgspouts;