예제 #1
0
    def test_timers_data(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.timers_data())

        shelf.add(Timer("query.user", 3.223))
        shelf.add(Timer("query.user", 4.12))
        shelf.add(Timer("api.auth", 9.78))
        shelf.add(Timer("api.auth", 8.45))

        expected = {"query.user": [3.223, 4.12], "api.auth": [9.78, 8.45]}
        self.assertEqual(expected, shelf.timers_data())
예제 #2
0
    def test_counters(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.counters())

        shelf.add(Counter("mymetric", 3))
        shelf.add(Counter("mymetric", 2))
        shelf.add(Counter("something.else", 2, 0.5))
        expected = {"mymetric": 5, "something.else": 4}
        self.assertEqual(expected, shelf.counters())

        counters = shelf.counters()
        counters["counters should"] = "not changed"
        self.assertEqual(expected, shelf.counters())
예제 #3
0
    def test_timers_data(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.timers_data())

        shelf.add(Timer("query.user", 3.223))
        shelf.add(Timer("query.user", 4.12))
        shelf.add(Timer("api.auth", 9.78))
        shelf.add(Timer("api.auth", 8.45))

        expected = {"query.user": [3.223, 4.12], "api.auth": [9.78, 8.45]}
        self.assertEqual(expected, shelf.timers_data())
예제 #4
0
    def test_counters(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.counters())

        shelf.add(Counter("mymetric", 3))
        shelf.add(Counter("mymetric", 2))
        shelf.add(Counter("something.else", 2, 0.5))
        expected = {"mymetric": 5, "something.else": 4}
        self.assertEqual(expected, shelf.counters())

        counters = shelf.counters()
        counters["counters should"] = "not changed"
        self.assertEqual(expected, shelf.counters())
예제 #5
0
    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())
예제 #6
0
    def test_timers(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.timers())

        shelf.add(Timer("query.user", 2.9))
        shelf.add(Timer("query.user", 3))
        shelf.add(Timer("query.user", 4.1))
        shelf.add(Timer("api.auth", 8))
        shelf.add(Timer("api.auth", 7.96))
        shelf.add(Timer("cache.clear", 1.56))

        expected = {
            "query.user": dict(count=3, min=2.9, max=4.1, mean=3.3333333333333335, median=3),
            "api.auth": dict(count=2, min=7.96, max=8, mean=7.98, median=7.98),
            "cache.clear": dict(count=1, min=1.56, max=1.56, mean=1.56, median=1.56),
        }
        self.assertEqual(expected, shelf.timers())
예제 #7
0
    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())
예제 #8
0
    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())
예제 #9
0
    def test_sets(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.sets())

        shelf.add(Set("users", "me"))
        shelf.add(Set("users", "me"))
        shelf.add(Set("users", "you"))
        shelf.add(Set("say.what?", "nothing"))
        shelf.add(Set("users", "me"))
        shelf.add(Set("say.what?", "nothing"))
        shelf.add(Set("say.what?", "ok"))
        expected = {"users": {"me", "you"},
                    "say.what?": {"nothing", "ok"}}
        self.assertEqual(expected, shelf.sets())

        sets = shelf.sets()
        sets["sets should"] = set("not change")
        self.assertEqual(expected, shelf.sets())
예제 #10
0
    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())
예제 #11
0
    def test_timers(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.timers())

        shelf.add(Timer("query.user", 2.9))
        shelf.add(Timer("query.user", 3))
        shelf.add(Timer("query.user", 4.1))
        shelf.add(Timer("api.auth", 8))
        shelf.add(Timer("api.auth", 7.96))
        shelf.add(Timer("cache.clear", 1.56))

        expected = {
            "query.user":
            dict(count=3, min=2.9, max=4.1, mean=3.3333333333333335, median=3),
            "api.auth":
            dict(count=2, min=7.96, max=8, mean=7.98, median=7.98),
            "cache.clear":
            dict(count=1, min=1.56, max=1.56, mean=1.56, median=1.56),
        }
        self.assertEqual(expected, shelf.timers())
예제 #12
0
    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())
예제 #13
0
    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())
예제 #14
0
    def test_sets(self):
        shelf = StatsShelf()
        self.assertEqual(dict(), shelf.sets())

        shelf.add(Set("users", "me"))
        shelf.add(Set("users", "me"))
        shelf.add(Set("users", "you"))
        shelf.add(Set("say.what?", "nothing"))
        shelf.add(Set("users", "me"))
        shelf.add(Set("say.what?", "nothing"))
        shelf.add(Set("say.what?", "ok"))
        expected = {"users": {"me", "you"}, "say.what?": {"nothing", "ok"}}
        self.assertEqual(expected, shelf.sets())

        sets = shelf.sets()
        sets["sets should"] = set("not change")
        self.assertEqual(expected, shelf.sets())