def test_gauge_deltas(self): shelf = StatsShelf() self.assertEqual(dict(), shelf.gauges()) shelf.add(GaugeDelta("cpu%", 10)) shelf.add(Gauge("mem%", 10)) shelf.add(GaugeDelta("cpu%", 10)) shelf.add(GaugeDelta("cpu%", -5)) shelf.add(GaugeDelta("mem%", -2)) shelf.add(GaugeDelta("mem%", 4)) expected = {"cpu%": 15, "mem%": 12} self.assertEqual(expected, shelf.gauges())
def test_gauges(self): shelf = StatsShelf() self.assertEqual(dict(), shelf.gauges()) shelf.add(Gauge("cpu%", 50)) shelf.add(Gauge("cpu%", 51)) shelf.add(Gauge("mem%", 20)) shelf.add(Gauge("mem%", 23)) shelf.add(Gauge("cpu%", 58)) expected = {"cpu%": 58, "mem%": 23} self.assertEqual(expected, shelf.gauges()) gauges = shelf.gauges() gauges["gauges should"] = "not change" self.assertEqual(expected, shelf.gauges())
def test_clear_all_metrics(self): shelf = StatsShelf() shelf.add(Set("users", "me")) shelf.add(Counter("mymetric", 3)) shelf.add(Timer("query", 4.12)) shelf.add(Gauge("cpu%", 38)) shelf.clear() self.assertEqual(dict(), shelf.counters()) self.assertEqual(dict(), shelf.sets()) self.assertEqual(dict(), shelf.timers_data()) self.assertEqual(dict(), shelf.gauges())