示例#1
0
    def _sanitize(alarm, statistics):
        """Sanitize statistics."""
        LOG.debug("sanitize stats %s", statistics)
        if alarm.rule.get("exclude_outliers"):
            key = operator.attrgetter("count")
            mean = utils.mean(statistics, key)
            stddev = utils.stddev(statistics, key, mean)
            lower = mean - 2 * stddev
            upper = mean + 2 * stddev
            inliers, outliers = utils.anomalies(statistics, key, lower, upper)
            if outliers:
                LOG.debug("excluded weak datapoints with sample counts %s", [s.count for s in outliers])
                statistics = inliers
            else:
                LOG.debug("no excluded weak datapoints")

        # in practice statistics are always sorted by period start, not
        # strictly required by the API though
        statistics = statistics[-alarm.rule["evaluation_periods"] :]
        LOG.debug("pruned statistics to %d", len(statistics))
        return statistics
示例#2
0
    def _sanitize(alarm, statistics):
        """Sanitize statistics."""
        LOG.debug(_('sanitize stats %s') % statistics)
        if alarm.rule.get('exclude_outliers'):
            key = operator.attrgetter('count')
            mean = utils.mean(statistics, key)
            stddev = utils.stddev(statistics, key, mean)
            lower = mean - 2 * stddev
            upper = mean + 2 * stddev
            inliers, outliers = utils.anomalies(statistics, key, lower, upper)
            if outliers:
                LOG.debug(_('excluded weak datapoints with sample counts %s'),
                          [s.count for s in outliers])
                statistics = inliers
            else:
                LOG.debug('no excluded weak datapoints')

        # in practice statistics are always sorted by period start, not
        # strictly required by the API though
        statistics = statistics[-alarm.rule['evaluation_periods']:]
        LOG.debug(_('pruned statistics to %d') % len(statistics))
        return statistics