Exemple #1
0
 def test_delta_should_be_numeric(self):
     self.assertRaises(AssertionError, GaugeDelta, 'string_val', '')
     gauge_delta = GaugeDelta('ok', 0.3)
     gauge_delta.delta = 2.0
     self.assertEqual(gauge_delta.delta, 2.0)
     gauge_delta.delta = 27
     self.assertEqual(gauge_delta.delta, 27)
 def test_delta_should_be_numeric(self):
     self.assertRaises(AssertionError, GaugeDelta, 'string_val', '')
     gauge_delta = GaugeDelta('ok', 0.3)
     gauge_delta.delta = 2.0
     self.assertEqual(gauge_delta.delta, 2.0)
     gauge_delta.delta = 27
     self.assertEqual(gauge_delta.delta, 27)
Exemple #3
0
    def test_to_request(self):
        gauge_delta = GaugeDelta('ok', 0.2)
        self.assertEqual(gauge_delta.to_request(), 'ok:+0.2|g')

        gauge_delta2 = GaugeDelta('another', -43)
        self.assertEqual(gauge_delta2.to_request(), 'another:-43|g')

        gauge_delta3 = GaugeDelta('again', 15, 0.4)
        self.assertEqual(gauge_delta3.to_request(), 'again:+15|g|@0.4')
    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())
Exemple #5
0
 def test_parse_gauge_delta_metric_from_request(self):
     self.assertEqual(
         GaugeDelta("cpu_usage", 6),
         parse_metric_from_request("cpu_usage:+6|g")
     )
     self.assertEqual(
         GaugeDelta("mem usage?", -2048, 1),
         parse_metric_from_request("mem usage?:-2048|g|@1")
     )
     self.assertEqual(
         GaugeDelta("weird.gauge.delta.with.rate", 23.3, 0.5),
         parse_metric_from_request(
             "weird.gauge.delta.with.rate:+23.3|g|@0.5")
     )
Exemple #6
0
    def test_equality_check(self):
        metric = GaugeDelta('cpu', 5)
        with self.assertRaises(AssertionError):
            metric != 'I am not a GaugeDelta'

        different_name = GaugeDelta('memory', 5)
        self.assertTrue(metric != different_name)

        different_value = GaugeDelta('cpu', 25)
        self.assertTrue(metric != different_value)

        different_rate = GaugeDelta('cpu', 5, 0.5)
        self.assertTrue(metric != different_rate)

        same = GaugeDelta('cpu', 5)
        self.assertTrue(same == metric)
    def test_to_request(self):
        gauge_delta = GaugeDelta('ok', 0.2)
        self.assertEqual(gauge_delta.to_request(), 'ok:+0.2|g')

        gauge_delta2 = GaugeDelta('another', -43)
        self.assertEqual(gauge_delta2.to_request(), 'another:-43|g')

        gauge_delta3 = GaugeDelta('again', 15, 0.4)
        self.assertEqual(gauge_delta3.to_request(), 'again:+15|g|@0.4')
Exemple #8
0
 def test_constructor(self):
     gauge_delta = GaugeDelta('unique', 5)
     self.assertEqual(gauge_delta.name, 'unique')
     self.assertEqual(gauge_delta.delta, 5)