Exemplo n.º 1
0
    def test_udp_send_batch(self, mock):
        self.reporter = StatsDReporter('localhost',
                                       3333,
                                       batch_size=2,
                                       conn_type='udp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendto.called)
        self.assertEqual(3, len(mock.sendto.call_args_list))
        self.reporter.stop()
Exemplo n.º 2
0
    def test_udp_send_batch(self, mock):
        self.reporter = StatsDReporter('localhost', 3333,
                                       batch_size=2, conn_type='udp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendto.called)
        self.assertEqual(3, len(mock.sendto.call_args_list))
        self.reporter.stop()
Exemplo n.º 3
0
class StatsDReporterTest(TestCase):
    def tearDown(self):
        Metrology.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_send_nobatch(self, mock):
        self.reporter = StatsDReporter('localhost',
                                       3333,
                                       batch_size=1,
                                       conn_type='tcp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendall.called)
        self.assertEqual(6, len(mock.sendall.call_args_list))
        self.reporter.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_send_batch(self, mock):
        self.reporter = StatsDReporter('localhost',
                                       3333,
                                       batch_size=2,
                                       conn_type='tcp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendall.called)
        self.assertEqual(3, len(mock.sendall.call_args_list))
        self.reporter.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_udp_send_nobatch(self, mock):
        self.reporter = StatsDReporter('localhost',
                                       3333,
                                       batch_size=1,
                                       conn_type='udp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendto.called)
        self.assertEqual(6, len(mock.sendto.call_args_list))
        self.reporter.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_udp_send_batch(self, mock):
        self.reporter = StatsDReporter('localhost',
                                       3333,
                                       batch_size=2,
                                       conn_type='udp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendto.called)
        self.assertEqual(3, len(mock.sendto.call_args_list))
        self.reporter.stop()
Exemplo n.º 4
0
    metrics = {}
    for name, type_ in metric_definitions.items():
        metrics[name] = type_(",".join((name, METRIC_TAGS)))
    return metrics


# Register the metrics we intend to update and send.
METRICS = register_metrics({
    "root.requests": Metrology.counter,
})

# Configure reporter to send metrics to statsd.
if STATSD_HOST:
    from metrology.reporter.statsd import StatsDReporter
    reporter = StatsDReporter(host=STATSD_HOST,
                              port=int(STATSD_PORT),
                              interval=int(STATSD_INTERVAL))

    reporter.start()

# Create the Flask app.
app = Flask(__name__)


@app.route("/")
def root():
    # Update a pre-registered metric.
    METRICS["root.requests"].increment()
    return "Hello! (python-metrology)"

Exemplo n.º 5
0
class StatsDReporterTest(TestCase):
    def tearDown(self):
        Metrology.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_send_nobatch(self, mock):
        self.reporter = StatsDReporter('localhost', 3333,
                                       batch_size=1, conn_type='tcp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendall.called)
        self.assertEqual(6, len(mock.sendall.call_args_list))
        self.reporter.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_send_batch(self, mock):
        self.reporter = StatsDReporter('localhost', 3333,
                                       batch_size=2, conn_type='tcp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendall.called)
        self.assertEqual(3, len(mock.sendall.call_args_list))
        self.reporter.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_udp_send_nobatch(self, mock):
        self.reporter = StatsDReporter('localhost', 3333,
                                       batch_size=1, conn_type='udp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendto.called)
        self.assertEqual(6, len(mock.sendto.call_args_list))
        self.reporter.stop()

    @patch.object(StatsDReporter, 'socket')
    def test_udp_send_batch(self, mock):
        self.reporter = StatsDReporter('localhost', 3333,
                                       batch_size=2, conn_type='udp')

        Metrology.meter('meter').mark()
        Metrology.counter('counter').increment()
        Metrology.timer('timer').update(5)
        Metrology.utilization_timer('utimer').update(5)
        Metrology.histogram('histogram').update(5)
        self.reporter.write()
        self.assertTrue(mock.sendto.called)
        self.assertEqual(3, len(mock.sendto.call_args_list))
        self.reporter.stop()