Example #1
0
    def test_scalar(self):
        d = dict()

        metric = CallbackMetric("size", lambda: len(d))

        self.assertEquals(metric.render(), [
            'size 0',
        ])

        d["key"] = "value"

        self.assertEquals(metric.render(), [
            'size 1',
        ])
Example #2
0
    def test_scalar(self):
        d = dict()

        metric = CallbackMetric("size", lambda: len(d))

        self.assertEquals(metric.render(), [
            'size 0',
        ])

        d["key"] = "value"

        self.assertEquals(metric.render(), [
            'size 1',
        ])
Example #3
0
    def test_vector(self):
        vals = dict()

        metric = CallbackMetric("values", lambda: vals, labels=["type"])

        self.assertEquals(metric.render(), [])

        # Keys have to be tuples, even if they're 1-element
        vals[("foo", )] = 1
        vals[("bar", )] = 2

        self.assertEquals(metric.render(), [
            'values{type="bar"} 2',
            'values{type="foo"} 1',
        ])
Example #4
0
    def test_vector(self):
        vals = dict()

        metric = CallbackMetric("values", lambda: vals, labels=["type"])

        self.assertEquals(metric.render(), [])

        # Keys have to be tuples, even if they're 1-element
        vals[("foo",)] = 1
        vals[("bar",)] = 2

        self.assertEquals(metric.render(), [
            'values{type="bar"} 2',
            'values{type="foo"} 1',
        ])