Example #1
0
 def test_report_now(self):
     r = CarbonReporter(registry=self.registry,
                        reporting_interval=1,
                        clock=self.clock,
                        socket_factory=lambda: self)
     h1 = self.registry.histogram("hist")
     for i in range(10):
         h1.add(2**i)
     gcb = self.registry.gauge("gcb", lambda: 123)
     gsimple = self.registry.gauge("gsimple").set_value(42)
     t1 = self.registry.timer("t1")
     m1 = self.registry.meter("m1")
     m1.mark()
     with t1.time():
         c1 = self.registry.counter("c1")
         c2 = self.registry.counter("counter-2")
         c1.inc()
         c2.dec()
         c2.dec()
         self.clock.add(1)
     r.report_now()
     self.assertEqual(self.output.getvalue().splitlines(), [
         'counter-2.count -2 1', 'gsimple.value 42 1', 'gcb.value 123 1',
         't1.1m_rate 0 1', 't1.999_percentile 1 1', 't1.15m_rate 0 1',
         't1.99_percentile 1 1', 't1.mean_rate 1.0 1',
         't1.95_percentile 1 1', 't1.min 1 1', 't1.5m_rate 0 1',
         't1.count 1.0 1', 't1.75_percentile 1 1', 't1.std_dev 0.0 1',
         't1.max 1 1', 't1.avg 1.0 1', 'hist.count 10.0 1',
         'hist.999_percentile 512 1', 'hist.99_percentile 512 1',
         'hist.min 1 1', 'hist.95_percentile 512 1',
         'hist.75_percentile 160.0 1', 'hist.std_dev 164.948510485 1',
         'hist.max 512 1', 'hist.avg 102.3 1', 'm1.1m_rate 0 1',
         'm1.15m_rate 0 1', 'm1.5m_rate 0 1', 'm1.mean_rate 1.0 1',
         'c1.count 1 1'
     ])
def create_reporter(app):
    if "GRAPHITE_HOST" in app.config:
        from pyformance.reporters.carbon_reporter import CarbonReporter
        reporter = CarbonReporter(prefix=app.config["GRAPHITE_PREFIX"],
                                  server=app.config["GRAPHITE_HOST"],
                                  reporting_interval=30)
        reporter.start()
 def test_report_now(self):
     r = CarbonReporter(
         registry=self.registry, reporting_interval=1, clock=self.clock,
         socket_factory=lambda: self)
     h1 = self.registry.histogram("hist")
     for i in range(10):
         h1.add(2 ** i)
     gcb = self.registry.gauge("gcb", lambda: 123)
     gsimple = self.registry.gauge("gsimple").set_value(42)
     t1 = self.registry.timer("t1")
     m1 = self.registry.meter("m1")
     m1.mark()
     with t1.time():
         c1 = self.registry.counter("c1")
         c2 = self.registry.counter("counter-2")
         c1.inc()
         c2.dec()
         c2.dec()
         self.clock.add(1)
     r.report_now()
     self.assertEqual([
         'counter-2.count -2 1',
         'c1.count 1 1',
         'gsimple.value 42 1',
         'gcb.value 123 1',
         't1.1m_rate 0 1',
         't1.999_percentile 1 1',
         't1.15m_rate 0 1',
         't1.99_percentile 1 1',
         't1.mean_rate 1.0 1',
         't1.95_percentile 1 1',
         't1.min 1 1',
         't1.5m_rate 0 1',
         't1.count 1.0 1',
         't1.75_percentile 1 1',
         't1.std_dev 0.0 1',
         't1.max 1 1',
         't1.avg 1.0 1',
         'hist.count 10.0 1',
         'hist.999_percentile 512 1',
         'hist.99_percentile 512 1',
         'hist.min 1 1',
         'hist.95_percentile 512 1',
         'hist.75_percentile 160.0 1',
         'hist.std_dev 164.948510485 1',
         'hist.max 512 1',
         'hist.avg 102.3 1',
         'm1.count 1.0 1',
         'm1.1m_rate 0 1',
         'm1.15m_rate 0 1',
         'm1.5m_rate 0 1',
         'm1.mean_rate 1.0 1',
     ].sort(),
         self.output.getvalue().splitlines().sort())
 def test_report_now_plain(self):
     r = CarbonReporter(
         registry=self.registry,
         reporting_interval=1,
         clock=self.clock,
         socket_factory=lambda: self,
     )
     self.capture_test_metrics()
     r.report_now()
     test_data = sorted(self.output.getvalue().decode().splitlines())
     expected_data = sorted(
         [
             "counter-2.count -2 2",
             "c1.count 1 2",
             "gsimple.value 42 2",
             "gcb.value 123 2",
             "t1.1m_rate 0 2",
             "t1.999_percentile 1 2",
             "t1.15m_rate 0 2",
             "t1.99_percentile 1 2",
             "t1.mean_rate 1.0 2",
             "t1.95_percentile 1 2",
             "t1.min 1 2",
             "t1.50_percentile 1 2",
             "t1.5m_rate 0 2",
             "t1.count 1.0 2",
             "t1.75_percentile 1 2",
             "t1.std_dev 0.0 2",
             "t1.max 1 2",
             "t1.sum 1.0 2",
             "t1.avg 1.0 2",
             "hist.count 10.0 2",
             "hist.999_percentile 512 2",
             "hist.99_percentile 512 2",
             "hist.min 1 2",
             "hist.95_percentile 512 2",
             "hist.75_percentile 160.0 2",
             "hist.std_dev 164.94851048466944 2"
             if PY3
             else "hist.std_dev 164.948510485 2",
             "hist.max 512 2",
             "hist.avg 102.3 2",
             "m1.count 1.0 2",
             "m1.1m_rate 0 2",
             "m1.15m_rate 0 2",
             "m1.5m_rate 0 2",
             "m1.mean_rate 1.0 2",
         ]
     )
     self.assertEqual(test_data, expected_data)
 def test_report_now_pickle(self):
     r = CarbonReporter(
         registry=self.registry,
         reporting_interval=1,
         clock=self.clock,
         socket_factory=lambda: self,
         pickle_protocol=True,
     )
     self.capture_test_metrics()
     r.report_now()
     test_data = sorted(pickle.loads(self.output.getvalue()[4:]))
     expected_data = sorted(
         [
             ("counter-2.count", (2, -2.0)),
             ("c1.count", (2, 1)),
             ("gsimple.value", (2, 42.0)),
             ("gcb.value", (2, 123.0)),
             ("t1.1m_rate", (2, 0.0)),
             ("t1.999_percentile", (2, 1)),
             ("t1.15m_rate", (2, 0.0)),
             ("t1.99_percentile", (2, 1)),
             ("t1.mean_rate", (2, 1)),
             ("t1.95_percentile", (2, 1)),
             ("t1.min", (2, 1)),
             ("t1.50_percentile", (2, 1)),
             ("t1.5m_rate", (2, 0.0)),
             ("t1.count", (2, 1)),
             ("t1.75_percentile", (2, 1)),
             ("t1.std_dev", (2, 0.0)),
             ("t1.max", (2, 1)),
             ("t1.sum", (2, 1)),
             ("t1.avg", (2, 1)),
             ("hist.count", (2, 10.0)),
             ("hist.999_percentile", (2, 512.0)),
             ("hist.99_percentile", (2, 512.0)),
             ("hist.min", (2, 1)),
             ("hist.95_percentile", (2, 512.0)),
             ("hist.75_percentile", (2, 160.0)),
             ("hist.std_dev", (2, 164.94851048466944)),
             ("hist.max", (2, 512.0)),
             ("hist.avg", (2, 102.3)),
             ("m1.count", (2, 1)),
             ("m1.1m_rate", (2, 0.0)),
             ("m1.15m_rate", (2, 0.0)),
             ("m1.5m_rate", (2, 0.0)),
             ("m1.mean_rate", (2, 1)),
         ]
     )
     self.assertEqual(test_data, expected_data)
Example #6
0
 def test_report_now_plain(self):
     r = CarbonReporter(
         registry=self.registry,
         reporting_interval=1,
         clock=self.clock,
         socket_factory=lambda: self,
     )
     self.capture_test_metrics()
     r.report_now()
     test_data = sorted(self.output.getvalue().decode().splitlines())
     expected_data = sorted([
         "counter-2.count -2 2",
         "c1.count 1 2",
         "gsimple.value 42 2",
         "e1.field 1 2",
         "gcb.value 123 2",
         "t1.1m_rate 0 2",
         "t1.999_percentile 1 2",
         "t1.15m_rate 0 2",
         "t1.99_percentile 1 2",
         "t1.mean_rate 1.0 2",
         "t1.95_percentile 1 2",
         "t1.min 1 2",
         "t1.50_percentile 1 2",
         "t1.5m_rate 0 2",
         "t1.count 1.0 2",
         "t1.75_percentile 1 2",
         "t1.std_dev 0.0 2",
         "t1.max 1 2",
         "t1.sum 1.0 2",
         "t1.avg 1.0 2",
         "hist.count 10.0 2",
         "hist.999_percentile 512 2",
         "hist.99_percentile 512 2",
         "hist.min 1 2",
         "hist.95_percentile 512 2",
         "hist.75_percentile 160.0 2",
         "hist.std_dev 164.94851048466944 2"
         if PY3 else "hist.std_dev 164.948510485 2",
         "hist.max 512 2",
         "hist.avg 102.3 2",
         "m1.count 1.0 2",
         "m1.1m_rate 0 2",
         "m1.15m_rate 0 2",
         "m1.5m_rate 0 2",
         "m1.mean_rate 1.0 2",
     ])
     self.assertEqual(test_data, expected_data)
Example #7
0
 def test_report_now_pickle(self):
     r = CarbonReporter(
         registry=self.registry,
         reporting_interval=1,
         clock=self.clock,
         socket_factory=lambda: self,
         pickle_protocol=True,
     )
     self.capture_test_metrics()
     r.report_now()
     test_data = sorted(pickle.loads(self.output.getvalue()[4:]))
     expected_data = sorted([
         ("counter-2.count", (2, -2.0)),
         ("c1.count", (2, 1)),
         ("gsimple.value", (2, 42.0)),
         ("gcb.value", (2, 123.0)),
         ("t1.1m_rate", (2, 0.0)),
         ("t1.999_percentile", (2, 1)),
         ("t1.15m_rate", (2, 0.0)),
         ("t1.99_percentile", (2, 1)),
         ("t1.mean_rate", (2, 1)),
         ("t1.95_percentile", (2, 1)),
         ("t1.min", (2, 1)),
         ("t1.50_percentile", (2, 1)),
         ("t1.5m_rate", (2, 0.0)),
         ("t1.count", (2, 1)),
         ("t1.75_percentile", (2, 1)),
         ("t1.std_dev", (2, 0.0)),
         ("t1.max", (2, 1)),
         ("t1.sum", (2, 1)),
         ("t1.avg", (2, 1)),
         ("hist.count", (2, 10.0)),
         ("hist.999_percentile", (2, 512.0)),
         ("hist.99_percentile", (2, 512.0)),
         ("hist.min", (2, 1)),
         ("hist.95_percentile", (2, 512.0)),
         ("hist.75_percentile", (2, 160.0)),
         ("hist.std_dev", (2, 164.94851048466944)),
         ("hist.max", (2, 512.0)),
         ("hist.avg", (2, 102.3)),
         ("m1.count", (2, 1)),
         ("m1.1m_rate", (2, 0.0)),
         ("m1.15m_rate", (2, 0.0)),
         ("m1.5m_rate", (2, 0.0)),
         ("m1.mean_rate", (2, 1)),
     ])
     self.assertEqual(test_data, expected_data)