def test_hour_stats_with_no_hour_overlap(self): s = stats.SamplerStats(self.createFakeData(3600*3, 600, 6000), self.latest_time_sec+3600) hr_stats = s.last_hour_stats() self.assertEquals(0, hr_stats["quartile_1"]) self.assertEquals(0, hr_stats["median"]) self.assertEquals(0, hr_stats["quartile_3"]) self.assertEquals(0, hr_stats["percentile_95"]) self.assertEquals(0, hr_stats["largest_value"]) self.assertEquals(0, hr_stats["count"])
def test_hour_stats(self): s = stats.SamplerStats(self.createFakeData(3600*3, 600, 6000), self.latest_time_sec) hr_stats = s.last_hour_stats() self.assertEquals(50, hr_stats["quartile_1"]) self.assertEquals(100, hr_stats["median"]) self.assertEquals(150, hr_stats["quartile_3"]) self.assertEquals(190, hr_stats["percentile_95"]) self.assertEquals(199, hr_stats["largest_value"]) self.assertEquals(2000, hr_stats["count"])
def test_all_time_stats(self): s = stats.SamplerStats(self.createFakeData(), self.latest_time_sec) at_stats= s.all_time_stats() self.assertEquals(250, at_stats["quartile_1"]) self.assertEquals(500, at_stats["median"]) self.assertEquals(750, at_stats["quartile_3"]) self.assertEquals(950, at_stats["percentile_95"]) self.assertEquals(999, at_stats["largest_value"]) self.assertEquals(5000, at_stats["count"])
def test_last_minute_stats_returns_zeros_if_minutes_are_off(self): s = stats.SamplerStats(self.createFakeData(), self.latest_time_sec + 60) min_stats = s.last_minute_stats() self.assertEquals(0, min_stats["quartile_1"]) self.assertEquals(0, min_stats["median"]) self.assertEquals(0, min_stats["quartile_3"]) self.assertEquals(0, min_stats["percentile_95"]) self.assertEquals(0, min_stats["largest_value"]) self.assertEquals(0, min_stats["count"])
def test_last_minute_stats_returns_correctly_if_different_sec_but_same_min(self): s = stats.SamplerStats(self.createFakeData(), self.latest_time_sec + 59) min_stats = s.last_minute_stats() self.assertEquals(25, min_stats["quartile_1"]) self.assertEquals(50, min_stats["median"]) self.assertEquals(75, min_stats["quartile_3"]) self.assertEquals(95, min_stats["percentile_95"]) self.assertEquals(99, min_stats["largest_value"]) self.assertEquals(2000, min_stats["count"])
def test_last_minute_stats(self): s = stats.SamplerStats(self.createFakeData(), self.latest_time_sec) min_stats = s.last_minute_stats() self.assertEquals(25, min_stats["quartile_1"]) self.assertEquals(50, min_stats["median"]) self.assertEquals(75, min_stats["quartile_3"]) self.assertEquals(95, min_stats["percentile_95"]) self.assertEquals(99, min_stats["largest_value"]) self.assertEquals(2000, min_stats["count"])
def print_samplers(samplers, current_epoch_sec): print "%64s || %21s || %21s || %21s" % ( "", "Last Minute", "Last Hour", "All Time" ) print "%64s || %10s %10s || %10s %10s || %10s %10s" % ( "name", "median", "95th", "median", "95th", "median", "95th" ) print "-" * 150 for sampler_wrapper in samplers: sampler_stats = stats.SamplerStats(sampler_wrapper["value"], current_epoch_sec) minute_stats = sampler_stats.last_minute_stats() hour_stats = sampler_stats.last_hour_stats() all_time_stats = sampler_stats.all_time_stats() print "%64s || %10d %10d || %10d %10d || %10d %10d" % \ (sampler_wrapper["name"], minute_stats["median"], minute_stats["percentile_95"], hour_stats["median"], hour_stats["percentile_95"], all_time_stats["median"], all_time_stats["percentile_95"])