X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fthreshold.c;h=38c7efb016d73a1d62bd10bb3efb0e5670caf1e1;hb=6bf2e82bf5049af097beae4a8b7f086466520839;hp=3c08e1fcc19cac6b60be0d734c5d4e79be4dcea2;hpb=68ac98ed21d932fc80dd2d296543564b7a06dac2;p=collectd.git diff --git a/src/threshold.c b/src/threshold.c index 3c08e1fc..38c7efb0 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -251,7 +251,6 @@ static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci) for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; - status = 0; if (strcasecmp ("Instance", option->key) == 0) status = ut_config_type_instance (&th, option); @@ -339,7 +338,6 @@ static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci) for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; - status = 0; if (strcasecmp ("Type", option->key) == 0) status = ut_config_type (&th, option); @@ -386,7 +384,6 @@ static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; - status = 0; if (strcasecmp ("Type", option->key) == 0) status = ut_config_type (&th, option); @@ -515,13 +512,12 @@ static int ut_report_state (const data_set_t *ds, if (state == STATE_OKAY) { if (state_old == STATE_MISSING) - status = ssnprintf (buf, bufsize, - ": Value is no longer missing."); + ssnprintf (buf, bufsize, ": Value is no longer missing."); else - status = ssnprintf (buf, bufsize, - ": All data sources are within range again."); - buf += status; - bufsize -= status; + ssnprintf (buf, bufsize, + ": All data sources are within range again. " + "Current value of \"%s\" is %f.", + ds->ds[ds_index].name, values[ds_index]); } else { @@ -535,7 +531,7 @@ static int ut_report_state (const data_set_t *ds, { if (!isnan (min) && !isnan (max)) { - status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " + ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is within the %s region of %f%s and %f%s.", ds->ds[ds_index].name, values[ds_index], (state == STATE_ERROR) ? "failure" : "warning", @@ -544,20 +540,20 @@ static int ut_report_state (const data_set_t *ds, } else { - status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " - "%f. That is %s the %s threshold of %f%s.", - ds->ds[ds_index].name, values[ds_index], - isnan (min) ? "below" : "above", - (state == STATE_ERROR) ? "failure" : "warning", - isnan (min) ? max : min, - ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); + ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " + "%f. That is %s the %s threshold of %f%s.", + ds->ds[ds_index].name, values[ds_index], + isnan (min) ? "below" : "above", + (state == STATE_ERROR) ? "failure" : "warning", + isnan (min) ? max : min, + ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); } } else if (th->flags & UT_FLAG_PERCENTAGE) { gauge_t value; gauge_t sum; - int i; + size_t i; sum = 0.0; for (i = 0; i < vl->values_len; i++) @@ -573,7 +569,7 @@ static int ut_report_state (const data_set_t *ds, else value = 100.0 * values[ds_index] / sum; - status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " + 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", @@ -582,15 +578,13 @@ static int ut_report_state (const data_set_t *ds, } else /* is not inverted */ { - status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " - "%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); + ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " + "%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); } - buf += status; - bufsize -= status; } plugin_dispatch_notification (&n); @@ -637,23 +631,40 @@ static int ut_check_one_data_source (const data_set_t *ds, /* XXX: This is an experimental code, not optimized, not fast, not reliable, * and probably, do not work as you expect. Enjoy! :D */ - if ( (th->hysteresis > 0) && ((prev_state = uc_get_state(ds,vl)) != STATE_OKAY) ) - { - switch(prev_state) + if (th->hysteresis > 0) + { + prev_state = uc_get_state(ds,vl); + /* The purpose of hysteresis is elliminating flapping state when the value + * oscilates around the thresholds. In other words, what is important is + * the previous state; if the new value would trigger a transition, make + * sure that we artificially widen the range which is considered to apply + * for the previous state, and only trigger the notification if the value + * is outside of this expanded range. + * + * There is no hysteresis for the OKAY state. + * */ + gauge_t hysteresis_for_warning = 0, hysteresis_for_failure = 0; + switch (prev_state) { case STATE_ERROR: - if ( (!isnan (th->failure_min) && ((th->failure_min + th->hysteresis) < values[ds_index])) || - (!isnan (th->failure_max) && ((th->failure_max - th->hysteresis) > values[ds_index])) ) - return (STATE_OKAY); - else - is_failure++; + hysteresis_for_failure = th->hysteresis; + break; case STATE_WARNING: - if ( (!isnan (th->warning_min) && ((th->warning_min + th->hysteresis) < values[ds_index])) || - (!isnan (th->warning_max) && ((th->warning_max - th->hysteresis) > values[ds_index])) ) - return (STATE_OKAY); - else - is_warning++; - } + hysteresis_for_warning = th->hysteresis; + break; + case STATE_OKAY: + /* do nothing -- the hysteresis only applies to the non-normal states */ + break; + } + + if ((!isnan (th->failure_min) && (th->failure_min + hysteresis_for_failure > values[ds_index])) + || (!isnan (th->failure_max) && (th->failure_max - hysteresis_for_failure < values[ds_index]))) + is_failure++; + + if ((!isnan (th->warning_min) && (th->warning_min + hysteresis_for_warning > values[ds_index])) + || (!isnan (th->warning_max) && (th->warning_max - hysteresis_for_warning < values[ds_index]))) + is_warning++; + } else { /* no hysteresis */ if ((!isnan (th->failure_min) && (th->failure_min > values[ds_index])) @@ -663,7 +674,7 @@ static int ut_check_one_data_source (const data_set_t *ds, if ((!isnan (th->warning_min) && (th->warning_min > values[ds_index])) || (!isnan (th->warning_max) && (th->warning_max < values[ds_index]))) is_warning++; - } + } if (is_failure != 0) return (STATE_ERROR); @@ -690,7 +701,7 @@ static int ut_check_one_threshold (const data_set_t *ds, { /* {{{ */ int ret = -1; int ds_index = -1; - int i; + size_t i; gauge_t values_copy[ds->ds_num]; memcpy (values_copy, values, sizeof (values_copy)); @@ -887,7 +898,6 @@ int ut_config (oconfig_item_t *ci) for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; - status = 0; if (strcasecmp ("Type", option->key) == 0) status = ut_config_type (&th, option);