Source
static void step(const zbx_vector_history_record_t *y, int n, int np, int ns, int nt, int nl, int isdeg, int itdeg,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
ZBX_PTR_VECTOR_DECL(VV, zbx_vector_history_record_t *)
ZBX_PTR_VECTOR_IMPL(VV, zbx_vector_history_record_t *)
/*******************************************************************************
* *
* Purpose: finds how many values in stl remainder are outliers. *
* *
* Parameters: remainder - [IN] stl remainder values vector *
* deviations_count - [IN] how much a value can be away from the *
* (mad, stdevsamp or stdevpop) to get *
* counted as an outlier *
* devalg - [IN] function (mad, stdevsamp or stdevpop) *
* to evaluate a single deviation unit *
* detect_period_start - [IN] evaluate number of deviations in *
* remainder starting from this time *
* detect_period - [IN] evaluate number of deviations in *
* remainder until this time *
* result - [OUT] result - double, a percentage how *
* many outliers are in remainder *
* error - [OUT] the error message *
* *
* Return value: SUCCEED - evaluated successfully, 'result' contains new value *
* FAIL - evaluation failed, 'result' contains old value *
* *
*******************************************************************************/
int zbx_get_percentage_of_deviations_in_stl_remainder(const zbx_vector_history_record_t *remainder,
double deviations_count, const char* devalg, int detect_period_start, int detect_period_end,
double *result, char **error)
{
int i, total_values_count = 0, deviations_detected_count = 0, ret = FAIL;
double remainder_deviation, deviation_limit;
zbx_statistical_func_t stat_func;
zbx_vector_dbl_t remainder_values_dbl;
zbx_vector_dbl_create(&remainder_values_dbl);
if (0 == remainder->values_num)
{
*error = zbx_strdup(*error, "empty remainder");
goto out;
}
if (0 == strcmp("mad", devalg))
{
stat_func = zbx_eval_calc_mad;
}
else if (0 == strcmp("stddevpop", devalg))
{
stat_func = zbx_eval_calc_stddevpop;
}
else if (0 == strcmp("stddevsamp", devalg))
{
stat_func = zbx_eval_calc_stddevsamp;
}
else
{
*error = zbx_dsprintf(*error, "undefined devalg parameter: \"%s\"", devalg);
THIS_SHOULD_NEVER_HAPPEN;
goto out;
}
zbx_vector_dbl_reserve(&remainder_values_dbl, (size_t)remainder->values_num);
for (i = 0; i < remainder->values_num; i++)
zbx_vector_dbl_append(&remainder_values_dbl, remainder->values[i].value.dbl);
if (SUCCEED != (ret = stat_func(&remainder_values_dbl, &remainder_deviation, error)))
goto out;
deviation_limit = remainder_deviation * deviations_count;