Beispiel #1
0
 def test_get_closest_datapoint(self):
     expect(get_closest_datapoint(self.timeseries, 10)).to.be.equal(
         TimeSeriesTuple('_', 10, 1))
     expect(get_closest_datapoint(self.timeseries, 40)).to.be.equal(
         TimeSeriesTuple('_', 30, 1))
     expect(get_closest_datapoint(self.timeseries, 99)).to.be.equal(
         TimeSeriesTuple('_', 100, 1))
Beispiel #2
0
    def read(self):
        quantile_25 = self.params['quantile_25']
        quantile_75 = self.params['quantile_75']
        metrics = self.params['metrics']
        delay = self.params.get('offset', 0)
        maximum_delay = self.params.get('maximum_delay', 600)

        # read metrics from metric_sink
        quantile_25 = [i for i in self.metric_sink.iread(quantile_25)]
        quantile_75 = [i for i in self.metric_sink.iread(quantile_75)]
        metrics = [i for i in self.metric_sink.iread(metrics)]
        if not (len(quantile_25) * len(quantile_75) * len(metrics)):
            self.logger.error(
                'No data found for quantile/to be checked metrics. Exiting')
            return None

        # sort TimeSeriesTuples by timestamp
        quantile_25 = sorted(quantile_25, key=lambda tup: tup.timestamp)
        quantile_75 = sorted(quantile_75, key=lambda tup: tup.timestamp)
        metrics = sorted(metrics, key=lambda tup: (tup.name, tup.timestamp))

        # find closest datapoint to now() (corrected by delay) if not too old
        time_now = time() - delay
        quantile_25 = get_closest_datapoint(quantile_25, time_now)
        if time_now - quantile_25.timestamp > maximum_delay:
            self.logger.error(
                'Quantile25 Value is too old (Timestamp: %d) of: %s. Exiting' %
                (quantile_25.timestamp, quantile_25.name))
            return None
        quantile_25 = quantile_25.value
        quantile_75 = get_closest_datapoint(quantile_75, time_now)
        if time_now - quantile_75.timestamp > maximum_delay:
            self.logger.error(
                'Quantile75 Value is too old (Timestamp: %d) of: %s. Exiting' %
                (quantile_75.timestamp, quantile_75.name))
            return None
        quantile_75 = quantile_75.value
        if quantile_25 > quantile_75:
            self.logger.error(
                'Inconsistent Quantile Values (Q25: %f, Q75: %f). Exiting' %
                (quantile_25, quantile_75))
            return None

        # group by metric (e.g. instance) first and find then closest datapoint
        distribution = {}
        grouped = itertools.groupby(metrics, key=lambda tup: tup.name)
        for key, metrics in grouped:
            closest_datapoint = get_closest_datapoint(
                [metric for metric in metrics], time_now)
            if time_now - closest_datapoint.timestamp < maximum_delay:
                distribution[key] = closest_datapoint.value
        if len(distribution) == 0:
            self.logger.error('No Distribution Values. Exiting')
            return None

        return quantile_25, quantile_75, distribution
    def read(self):
        quantile_25 = self.params['quantile_25']
        quantile_75 = self.params['quantile_75']
        metrics = self.params['metrics']
        delay = self.params.get('offset', 0)
        maximum_delay = self.params.get('maximum_delay', 600)

        # read metrics from metric_sink
        quantile_25 = [i for i in self.metric_sink.iread(quantile_25)]
        quantile_75 = [i for i in self.metric_sink.iread(quantile_75)]
        metrics = [i for i in self.metric_sink.iread(metrics)]
        if not (len(quantile_25) * len(quantile_75) * len(metrics)):
            self.logger.error(
                'No data found for quantile/to be checked metrics. Exiting')
            return None

        # sort TimeSeriesTuples by timestamp
        quantile_25 = sorted(quantile_25, key=lambda tup: tup.timestamp)
        quantile_75 = sorted(quantile_75, key=lambda tup: tup.timestamp)
        metrics = sorted(metrics, key=lambda tup: (tup.name, tup.timestamp))

        # find closest datapoint to now() (corrected by delay) if not too old
        time_now = time() - delay
        quantile_25 = get_closest_datapoint(quantile_25, time_now)
        if time_now - quantile_25.timestamp > maximum_delay:
            self.logger.error('Quantile25 Value is too old (Timestamp: %d) of: %s. Exiting' % (
                quantile_25.timestamp, quantile_25.name))
            return None
        quantile_25 = quantile_25.value
        quantile_75 = get_closest_datapoint(quantile_75, time_now)
        if time_now - quantile_75.timestamp > maximum_delay:
            self.logger.error('Quantile75 Value is too old (Timestamp: %d) of: %s. Exiting' % (
                quantile_75.timestamp, quantile_75.name))
            return None
        quantile_75 = quantile_75.value
        if quantile_25 > quantile_75:
            self.logger.error('Inconsistent Quantile Values (Q25: %f, Q75: %f). Exiting' % (
                quantile_25, quantile_75))
            return None

        # group by metric (e.g. instance) first and find then closest datapoint
        distribution = {}
        grouped = itertools.groupby(metrics, key=lambda tup: tup.name)
        for key, metrics in grouped:
            closest_datapoint = get_closest_datapoint(
                [metric for metric in metrics], time_now)
            if time_now - closest_datapoint.timestamp < maximum_delay:
                distribution[key] = closest_datapoint.value
        if len(distribution) == 0:
            self.logger.error('No Distribution Values. Exiting')
            return None

        return quantile_25, quantile_75, distribution
Beispiel #4
0
 def test_get_closest_datapoint(self):
     expect(get_closest_datapoint(self.timeseries, 10)).to.be.equal(TimeSeriesTuple('_', 10, 1))
     expect(get_closest_datapoint(self.timeseries, 40)).to.be.equal(TimeSeriesTuple('_', 30, 1))
     expect(get_closest_datapoint(self.timeseries, 99)).to.be.equal(TimeSeriesTuple('_', 100, 1))