def test_custom_multiple_percentile(self): configstr = '0.4, 0.65, 0.999' stats = MetricsAggregator( 'myhost', histogram_percentiles=get_histogram_percentiles(configstr) ) self.assertEquals( stats.metric_config[Histogram]['percentiles'], [0.4, 0.65, 0.99], stats.metric_config[Histogram] ) for i in xrange(20): stats.submit_packets('myhistogram:{0}|h'.format(i)) metrics = stats.flush() self.assertEquals(len(metrics), 7, metrics) value_by_type = {} for k in metrics: value_by_type[k['metric'][len('myhistogram')+1:]] = k['points'][0][1] self.assertEquals(value_by_type['40percentile'], 7, value_by_type) self.assertEquals(value_by_type['65percentile'], 12, value_by_type) self.assertEquals(value_by_type['99percentile'], 19, value_by_type)
def test_custom_single_percentile(self): configstr = '0.40' stats = MetricsAggregator( 'myhost', histogram_percentiles=get_histogram_percentiles(configstr) ) self.assertEquals( stats.metric_config[Histogram]['percentiles'], [0.40], stats.metric_config[Histogram] ) for i in xrange(20): stats.submit_packets('myhistogram:{0}|h'.format(i)) metrics = stats.flush() self.assertEquals(len(metrics), 5, metrics) value_by_type = {} for k in metrics: value_by_type[k[0][len('myhistogram')+1:]] = k[2] self.assertEquals(value_by_type['40percentile'], 7, value_by_type)
def test_custom_invalid_percentile3skip(self): configstr = 'aoeuoeu, 2.23, 0.8, 23' stats = MetricsAggregator( 'myhost', histogram_percentiles=get_histogram_percentiles(configstr)) self.assertEquals(stats.metric_config[Histogram]['percentiles'], [0.8], stats.metric_config[Histogram])
def test_custom_invalid_percentile(self): configstr = '1.2342' stats = MetricsAggregator( 'myhost', histogram_percentiles=get_histogram_percentiles(configstr)) self.assertEquals(stats.metric_config[Histogram]['percentiles'], [], stats.metric_config[Histogram])
def test_custom_invalid_percentile2(self): configstr = 'aoeuoeu' stats = MetricsAggregator('myhost', histogram_percentiles=get_histogram_percentiles(configstr) ) self.assertEquals( stats.metric_config[Histogram]['percentiles'], [], stats.metric_config[Histogram] )
def test_custom_single_percentile(self): configstr = '0.40' stats = MetricsAggregator( 'myhost', histogram_percentiles=get_histogram_percentiles(configstr)) self.assertEquals(stats.metric_config[Histogram]['percentiles'], [0.40], stats.metric_config[Histogram]) for i in xrange(20): stats.submit_packets('myhistogram:{0}|h'.format(i)) metrics = stats.flush() self.assertEquals(len(metrics), 5, metrics) value_by_type = {} for k in metrics: value_by_type[k[0][len('myhistogram') + 1:]] = k[2] self.assertEquals(value_by_type['40percentile'], 7, value_by_type)