Exemple #1
0
    def test_monasca_metrics_enabled(self, conn_mock):
        self.metrics = metrics.Metrics()

        self.assertIsInstance(self.metrics.client, monascastatsd.client.Client)
        self.assertIn('Statsd reports to 127.0.0.1:8125',
                      self.stdlog.logger.output)
        self.assertTrue(conn_mock.called)
Exemple #2
0
    def test_monasca_metrics_client_getters(self, conn_mock):
        self.metrics = metrics.Metrics()

        self.assertIsInstance(self.metrics.counter('name'),
                              monascastatsd.counter.Counter)
        self.assertIsInstance(self.metrics.gauge(),
                              monascastatsd.gauge.Gauge)
        self.assertIsInstance(self.metrics.timer(),
                              monascastatsd.timer.Timer)
        self.assertIsNotNone(self.metrics.timer.__self__)

        self.assertTrue(conn_mock.called)
Exemple #3
0
    def test_noop_metrics_client_timed(self):
        self.metrics = metrics.Metrics()
        timer = self.metrics.client.get_timer()

        def func(a):
            start_time = time.time()
            try:
                return a
            finally:
                timer.timing('mdns.xfr.zone_sync', time.time() - start_time)

        result = func(1)
        self.assertEqual(result, 1)
Exemple #4
0
 def test_monasca_enabled_but_client_not_installed(self):
     restore = metrics.monascastatsd
     try:
         metrics.monascastatsd = None
         self.metrics = metrics.Metrics()
         self.assertIsInstance(self.metrics.client, noop.Client)
         self.assertIn(
             'monasca-statsd client not installed. '
             'Metrics will be ignored.',
             self.stdlog.logger.output
         )
     finally:
         metrics.monascastatsd = restore
Exemple #5
0
    def test_monasca_metrics_client_timed(self, conn_mock, send_mock):
        self.metrics = metrics.Metrics()
        timer = self.metrics.client.get_timer()

        def func(a):
            start_time = time.time()
            try:
                return a
            finally:
                timer.timing('mdns.xfr.zone_sync', time.time() - start_time)

        result = func(1)
        self.assertEqual(result, 1)
        self.assertTrue(conn_mock.called)
        self.assertTrue(send_mock.called)
Exemple #6
0
 def test_noop_metrics_client_getters(self):
     self.metrics = metrics.Metrics()
     self.assertIsInstance(self.metrics.counter('name'), noop.NoopCounter)
     self.assertIsInstance(self.metrics.gauge(), noop.NoopGauge)
     self.assertIsInstance(self.metrics.timer(), noop.NoopTimer)
     self.assertIsNotNone(self.metrics.timer.__self__)
Exemple #7
0
 def test_monasca_metrics_disabled(self):
     self.metrics = metrics.Metrics()
     self.assertIsInstance(self.metrics.client, noop.Client)
     self.assertIn('Statsd disabled', self.stdlog.logger.output)