Exemplo n.º 1
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        duration = float(duration)
        metrics = []
        if duration > 0 and not self.raw_data:
            metrics += [
                MetricObject(counter, self.counts[counter] / duration)
                for counter in self.counts
            ]
        elif self.raw_data:
            metrics += [
                MetricObject(counter, self.counts[counter])
                for counter in self.counts
            ]
        for time_name in self.times:
            values = self.times[time_name]['values']
            unit = self.times[time_name]['unit']
            metrics.append(
                MetricObject(time_name + '.mean',
                             stats_helper.find_mean(values), unit))
            metrics.append(
                MetricObject(time_name + '.median',
                             stats_helper.find_median(values), unit))
            metrics += [
                MetricObject(
                    '%s.%sth_percentile' % (time_name, percentile),
                    stats_helper.find_percentile(values, int(percentile)),
                    unit) for percentile in self.percentiles
            ]

        return metrics
Exemplo n.º 2
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''

        self.duration = duration
        metrics = []

        # loop all the collected timers
        for time_name in self.times:
            values = self.times[time_name]['values']
            unit = self.times[time_name]['unit']
            # add counter
            if self.duration > 0:
                metrics.append(
                    MetricObject(time_name + '.count',
                                 len(values) / self.duration))
            # calculate statistical values
            metrics.append(
                MetricObject(time_name + '.mean',
                             stats_helper.find_mean(values), unit))
            metrics.append(
                MetricObject(time_name + '.median',
                             stats_helper.find_median(values), unit))
            metrics += [
                MetricObject(
                    '%s.%sth_percentile' % (time_name, percentile),
                    stats_helper.find_percentile(values, int(percentile)),
                    unit) for percentile in self.percentiles
            ]

        return metrics
Exemplo n.º 3
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''

        if len(self.waits) > 0:
            return [
                MetricObject("wait.min", min(self.waits)),
                MetricObject("wait.max", max(self.waits)),
                MetricObject("wait.mean", stats_helper.find_mean(self.waits)),
                MetricObject("wait.median", stats_helper.find_median(self.waits)),
                MetricObject("wait.90th_percentile", stats_helper.find_percentile(self.waits, 90)),
                MetricObject("wait.95th_percentile", stats_helper.find_percentile(self.waits, 95)),

                MetricObject("connect.min", min(self.connects)),
                MetricObject("connect.max", max(self.connects)),
                MetricObject("connect.mean", stats_helper.find_mean(self.connects)),
                MetricObject("connect.median", stats_helper.find_median(self.connects)),
                MetricObject("connect.90th_percentile", stats_helper.find_percentile(self.connects, 90)),
                MetricObject("connect.95th_percentile", stats_helper.find_percentile(self.connects, 95)),

                MetricObject("service.min", min(self.services)),
                MetricObject("service.max", max(self.services)),
                MetricObject("service.mean", stats_helper.find_mean(self.services)),
                MetricObject("service.median", stats_helper.find_median(self.services)),
                MetricObject("service.90th_percentile", stats_helper.find_percentile(self.services, 90)),
                MetricObject("service.95th_percentile", stats_helper.find_percentile(self.services, 95))
                ]
        else:
            return []
Exemplo n.º 4
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        metrics = []
        if duration > 0:
            metrics += [MetricObject(counter, self.counts[counter]/duration) for counter in self.counts]
        for time_name in self.times:
            values = self.times[time_name]['values']
            unit = self.times[time_name]['unit']
            metrics.append(MetricObject(time_name+'.mean', stats_helper.find_mean(values), unit))
            metrics.append(MetricObject(time_name+'.median', stats_helper.find_median(values), unit))
            metrics += [MetricObject('%s.%sth_percentile' % (time_name,percentile), stats_helper.find_percentile(values,int(percentile)), unit) for percentile in self.percentiles]

        return metrics
Exemplo n.º 5
0
 def test_10th_0_to_10(self):
     self.assertEqual(
         stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                                      10), 1)
Exemplo n.º 6
0
 def test_10th_0_to_10(self):
     self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10), 1)
Exemplo n.º 7
0
 def test_max_floats(self):
     self.assertEqual(stats_helper.find_percentile([0, 0.1, 1.5, 100], 100),
                      100)
Exemplo n.º 8
0
 def test_90th_1_to_11(self):
     self.assertEqual(
         stats_helper.find_percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
                                      90), 10)
Exemplo n.º 9
0
 def test_max_0_to_6(self):
     self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6], 100), 6)
Exemplo n.º 10
0
 def test_90th_0(self):
     self.assertEqual(stats_helper.find_percentile([0], 90), 0)
Exemplo n.º 11
0
 def test_90th_1_2_3(self):
     self.assertEqual(stats_helper.find_percentile([1, 2, 3], 90), 2.8)
Exemplo n.º 12
0
 def test_90th_1_minus1(self):
     self.assertEqual(stats_helper.find_percentile([1, -1], 90), 0.8)
Exemplo n.º 13
0
 def test_90th_1_to_11(self):
     self.assertEqual(stats_helper.find_percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 90), 10)
Exemplo n.º 14
0
 def test_90th_1_2(self):
     self.assertEqual(stats_helper.find_percentile([1, 2], 90), 1.9)
Exemplo n.º 15
0
 def test_90th_1_2_3(self):
     self.assertEqual(stats_helper.find_percentile([1, 2, 3], 90), 2.8)
Exemplo n.º 16
0
 def test_90th_0(self):
     self.assertEqual(stats_helper.find_percentile([0], 90), 0)
Exemplo n.º 17
0
 def test_12th_0_to_9(self):
     self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 12), 1.08)
Exemplo n.º 18
0
 def test_10th_1_to_3(self):
     self.assertEqual(stats_helper.find_percentile([1, 2, 3], 10), 1.2)
Exemplo n.º 19
0
 def test_10th_1_to_3(self):
     self.assertEqual(stats_helper.find_percentile([1, 2, 3], 10), 1.2)
Exemplo n.º 20
0
 def test_90th_1_to_15_noncontiguous(self):
     self.assertAlmostEqual(stats_helper.find_percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 15], 90), 9.6)
Exemplo n.º 21
0
 def test_12th_0_to_9(self):
     self.assertEqual(
         stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 12),
         1.08)
Exemplo n.º 22
0
 def test_max_0(self):
     self.assertEqual(stats_helper.find_percentile([0], 100), 0)
Exemplo n.º 23
0
 def test_90th_1_2(self):
     self.assertEqual(stats_helper.find_percentile([1, 2], 90), 1.9)
Exemplo n.º 24
0
 def test_max_0_to_11(self):
     self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 100), 11)
Exemplo n.º 25
0
 def test_90th_1_minus1(self):
     self.assertEqual(stats_helper.find_percentile([1, -1], 90), 0.8)
Exemplo n.º 26
0
 def test_max_0_to_3(self):
     self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3], 100), 3)
Exemplo n.º 27
0
 def test_90th_1_to_15_noncontiguous(self):
     self.assertAlmostEqual(
         stats_helper.find_percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 15], 90),
         9.6)
Exemplo n.º 28
0
 def test_max_0_to_11(self):
     self.assertEqual(
         stats_helper.find_percentile(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 100), 11)
Exemplo n.º 29
0
 def test_max_0_to_3(self):
     self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3], 100), 3)
Exemplo n.º 30
0
 def test_max_floats(self):
     self.assertEqual(stats_helper.find_percentile([0, 0.1, 1.5, 100], 100), 100)
Exemplo n.º 31
0
 def test_max_0_to_6(self):
     self.assertEqual(
         stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6], 100), 6)
Exemplo n.º 32
0
 def test_max_0(self):
     self.assertEqual(stats_helper.find_percentile([0], 100), 0)