X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_threshold.c;h=b14c79b5c6005bfdb86b9a3abfebb266a592897e;hb=772e60230767260801902eddd571bf6ff88c6423;hp=bfa868ce32e45df77f528cac156c428d54a65bf1;hpb=79c87aeda9172e219a842e393c6499c8bf37662a;p=collectd.git diff --git a/src/utils_threshold.c b/src/utils_threshold.c index bfa868ce..b14c79b5 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -1,6 +1,9 @@ /** * collectd - src/utils_threshold.c * Copyright (C) 2007-2009 Florian octo Forster + * Copyright (C) 2008-2009 Sebastian Harl + * Copyright (C) 2009 Andrés J. Díaz + * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -17,6 +20,8 @@ * * Author: * Florian octo Forster + * Sebastian Harl + * Andrés J. Díaz **/ #include "collectd.h" @@ -722,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;