summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cd3a0c6)
raw | patch | inline | side by side (parent: cd3a0c6)
author | Fabian Linzberger <e@lefant.net> | |
Mon, 3 Nov 2008 19:06:46 +0000 (20:06 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 9 Dec 2008 11:39:40 +0000 (12:39 +0100) |
the percentage aggregate function takes exactly two values. it
computes the percentage of the first value versus the sum of the first
and the second value. very useful for checking df values like:
sudo collectd-nagios -s /var/run/collectd-unixsock -H localhost -n df/df-root -d used -d free -g percentage -w 20: -c 10:
which will warn if there is less than 20% free space.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
computes the percentage of the first value versus the sum of the first
and the second value. very useful for checking df values like:
sudo collectd-nagios -s /var/run/collectd-unixsock -H localhost -n df/df-root -d used -d free -g percentage -w 20: -c 10:
which will warn if there is less than 20% free space.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
src/collectd-nagios.c | patch | blob | history |
diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c
index f37f78dde302b7cc2d22793282cf3415f516d96e..1d989cbd747ac9de096777d81c02760972c18db1 100644 (file)
--- a/src/collectd-nagios.c
+++ b/src/collectd-nagios.c
#define CON_NONE 0
#define CON_AVERAGE 1
#define CON_SUM 2
+#define CON_PERCENTAGE 3
struct range_s
{
return (status_code);
} /* int do_check_con_sum */
+static int do_check_con_percentage (int values_num, double *values, char **values_names)
+{
+ int i;
+ double percentage;
+
+ if (values_num != 2)
+ return (RET_WARNING);
+ if (isnan (values[0]) || isnan (values[1]))
+ return (RET_WARNING);
+ if ((values[0] + values[1]) == 0)
+ return (RET_WARNING);
+
+ percentage = 100 * values[1] / ( values[0] + values[1] );
+
+ printf ("%lf percentage |", percentage);
+ for (i = 0; i < values_num; i++)
+ printf (" %s=%lf;;;;", values_names[i], values[i]);
+
+ if (match_range (&range_critical_g, percentage) != 0)
+ {
+ printf ("CRITICAL: percentage = %lf\n", percentage);
+ return (RET_CRITICAL);
+ }
+ else if (match_range (&range_warning_g, percentage) != 0)
+ {
+ printf ("WARNING: percentage = %lf\n", percentage);
+ return (RET_WARNING);
+ }
+
+ printf ("OKAY: percentage = %lf\n", percentage);
+ return (RET_OKAY);
+} /* int do_check_con_percentage */
+
static int do_check (void)
{
lcc_connection_t *connection;
status = do_check_con_average (values_num, values, values_names);
else if (consolitation_g == CON_SUM)
status = do_check_con_sum (values_num, values, values_names);
+ else if (consolitation_g == CON_PERCENTAGE)
+ status = do_check_con_percentage (values_num, values, values_names);
free (values);
if (values_names != NULL)
consolitation_g = CON_AVERAGE;
else if (strcasecmp (optarg, "sum") == 0)
consolitation_g = CON_SUM;
+ else if (strcasecmp (optarg, "percentage") == 0)
+ consolitation_g = CON_PERCENTAGE;
else
usage (argv[0]);
break;