From: Florian Forster Date: Thu, 13 Jan 2011 07:57:24 +0000 (+0100) Subject: src/utils_threshold.c: Fix creation of percentage notifications. X-Git-Tag: collectd-4.9.5~11 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=77732cd2a61b8230a033bed8f82fe10d68e64da5;p=collectd.git src/utils_threshold.c: Fix creation of percentage notifications. Joey Hess has reported a problem when creating notifications from percentage thresholds. Because the (percentage) minimum value is compared to the (raw) DS value, the following message is possible: Message: Host XXX, plugin df type df (instance root): Data source "free" is currently 1773072384.000000. That is above the warning threshold of nan%. A new section will handle this case correctly. In the inverted case, the problem should not exist. --- diff --git a/src/utils_threshold.c b/src/utils_threshold.c index 090cc752..b14c79b5 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -727,15 +727,41 @@ static int ut_report_state (const data_set_t *ds, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); } } + else if (th->flags & UT_FLAG_PERCENTAGE) + { + gauge_t value; + gauge_t sum; + int i; + + sum = 0.0; + for (i = 0; i < vl->values_len; i++) + { + if (isnan (values[i])) + continue; + + sum += values[i]; + } + + if (sum == 0.0) + value = NAN; + else + value = 100.0 * values[ds_index] / sum; + + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " + "%g (%.2f%%). That is %s the %s threshold of %.2f%%.", + ds->ds[ds_index].name, values[ds_index], value, + (value < min) ? "below" : "above", + (state == STATE_ERROR) ? "failure" : "warning", + (value < min) ? min : max); + } else /* is not inverted */ { status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " - "%f. That is %s the %s threshold of %f%s.", + "%f. That is %s the %s threshold of %f.", ds->ds[ds_index].name, values[ds_index], (values[ds_index] < min) ? "below" : "above", (state == STATE_ERROR) ? "failure" : "warning", - (values[ds_index] < min) ? min : max, - ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); + (values[ds_index] < min) ? min : max); } buf += status; bufsize -= status;