All,
From a threshold/notification perspective, we find it useful to set
values based on percentages. Specifically, we'd like to set thresholds
on the percent of swap space in use, rather than on absolute kilobyte
values.
I've attached a patch that adds a "percent" metric to swap.c for all
currently enabled code paths. I've only verified functionality on
Solaris 10, but the changes were pretty straight forward for all
supported data sources. I did attempt to make my changes in the style of
the surrounding function
Ironically, I didn't touch the disabled Solaris 10 libkstat code, as the
comments indicated it belonged in vmem.c in the long term...
Please let me know if anyone tries out this patch and experiences
compilation or operational problems.
Thanks,
--Scott Severtson
--- collectd-5.1.0.orig/src/swap.c 2012-04-02 04:04:58.000000000 -0400
+++ collectd-5.1.0.patch/src/swap.c 2012-06-06 14:54:11.403945072 -0400
@@ -239,6 +239,7 @@
gauge_t size;
gauge_t used;
gauge_t free;
+ gauge_t percent;
numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (numfields != 5)
@@ -263,9 +264,11 @@
continue;
free = size - used;
+ percent = used / size * 100;
swap_submit_gauge (path, "used", used);
swap_submit_gauge (path, "free", free);
+ swap_submit_gauge (path, "percent", percent);
}
fclose (fh);
@@ -279,10 +282,12 @@
char buffer[1024];
uint8_t have_data = 0;
- gauge_t swap_used = 0.0;
- gauge_t swap_cached = 0.0;
- gauge_t swap_free = 0.0;
- gauge_t swap_total = 0.0;
+ gauge_t swap_used = 0.0;
+ gauge_t swap_cached = 0.0;
+ gauge_t swap_free = 0.0;
+ gauge_t swap_total = 0.0;
+ gauge_t swap_percent = 0.0;
+
fh = fopen ("/proc/meminfo", "r");
if (fh == NULL)
@@ -330,10 +335,12 @@
return (EINVAL);
swap_used = swap_total - (swap_free + swap_cached);
+ swap_percent = swap_used / swap_total * 100;
swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
+ swap_submit_gauge (NULL, "percent", swap_percent);
return (0);
} /* }}} int swap_read_combined */
@@ -582,6 +589,7 @@
swap_submit_gauge (path, "used", (gauge_t) (this_total - this_avail));
swap_submit_gauge (path, "free", (gauge_t) this_avail);
+ swap_submit_gauge (path, "percent", (gauge_t) ((this_total - this_avail) / this_total * 100));
} /* for (swap_num) */
if (total < avail)
@@ -600,6 +608,7 @@
{
swap_submit_gauge (NULL, "used", (gauge_t) (total - avail));
swap_submit_gauge (NULL, "free", (gauge_t) avail);
+ swap_submit_gauge (NULL, "percent", (gauge_t) (total - avail) / avail * 100);
}
sfree (s_paths);
@@ -672,6 +681,7 @@
swap_submit_gauge (NULL, "used", (gauge_t) used);
swap_submit_gauge (NULL, "free", (gauge_t) (total - used));
+ swap_submit_gauge (NULL, "percent", (gauge_t) (used / total * 100));
sfree (swap_entries);
@@ -699,6 +709,7 @@
/* The returned values are bytes. */
swap_submit_gauge (NULL, "used", (gauge_t) sw_usage.xsu_used);
swap_submit_gauge (NULL, "free", (gauge_t) sw_usage.xsu_avail);
+ swap_submit_gauge (NULL, "percent", (gauge_t) (sw_usage.xsu_used / (sw_usage.xsu_used + sw_usage.xsu_avail) * 100));
return (0);
} /* }}} int swap_read */
@@ -713,6 +724,7 @@
derive_t used;
derive_t free;
derive_t total;
+ derive_t percent;
if (kvm_obj == NULL)
return (-1);
@@ -729,9 +741,11 @@
used *= (derive_t) kvm_pagesize;
free = total - used;
+ percent = used / total * 100;
swap_submit_gauge (NULL, "used", (gauge_t) used);
swap_submit_gauge (NULL, "free", (gauge_t) free);
+ swap_submit_gauge (NULL, "percent", (gauge_t) percent);
return (0);
} /* }}} int swap_read */
@@ -749,6 +763,7 @@
swap_submit_gauge (NULL, "used", (gauge_t) swap->used);
swap_submit_gauge (NULL, "free", (gauge_t) swap->free);
+ swap_submit_gauge (NULL, "percent", (gauge_t) (swap->used / (swap->used + swap->free) * 100));
return (0);
} /* }}} int swap_read */
@@ -766,6 +781,7 @@
}
swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
+ swap_submit_gauge (NULL, "percent", (gauge_t) ((pmemory.pgsp_total - pmemory.pgsp_free) / pmemory.pgsp_total * 100) );
return (0);
} /* }}} int swap_read */
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd