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
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
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 []
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
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)
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)
def test_max_floats(self): self.assertEqual(stats_helper.find_percentile([0, 0.1, 1.5, 100], 100), 100)
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)
def test_max_0_to_6(self): self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6], 100), 6)
def test_90th_0(self): self.assertEqual(stats_helper.find_percentile([0], 90), 0)
def test_90th_1_2_3(self): self.assertEqual(stats_helper.find_percentile([1, 2, 3], 90), 2.8)
def test_90th_1_minus1(self): self.assertEqual(stats_helper.find_percentile([1, -1], 90), 0.8)
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)
def test_90th_1_2(self): self.assertEqual(stats_helper.find_percentile([1, 2], 90), 1.9)
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)
def test_10th_1_to_3(self): self.assertEqual(stats_helper.find_percentile([1, 2, 3], 10), 1.2)
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)
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)
def test_max_0(self): self.assertEqual(stats_helper.find_percentile([0], 100), 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)
def test_max_0_to_3(self): self.assertEqual(stats_helper.find_percentile([0, 1, 2, 3], 100), 3)
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)
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)
def test_max_0_to_6(self): self.assertEqual( stats_helper.find_percentile([0, 1, 2, 3, 4, 5, 6], 100), 6)