Ejemplo n.º 1
0
def initialize_mutornadomon(tornado_app=None, publisher=None, publish_interval=None,
                            host_limit=None, request_filter=None, **monitor_config):
    """Register mutornadomon to get Tornado request metrics"""
    if not publisher and not tornado_app:
        raise ValueError('Must pass at least one of `publisher` and `tornado_app`')

    if publisher:
        external_interface = PublishExternalInterface(publisher,
                                                      publish_interval=publish_interval)
    else:
        external_interface = HTTPEndpointExternalInterface(tornado_app,
                                                           request_filter=request_filter,
                                                           host_limit=host_limit)

    # Start collecting metrics and register endpoint with app
    monitor = MuTornadoMon(external_interface, **monitor_config)
    monitor.start()

    if tornado_app:
        web_collector = WebCollector(monitor, tornado_app)
        web_collector.start()

    utilization_collector = UtilizationCollector(monitor)
    utilization_collector.start()

    return monitor
Ejemplo n.º 2
0
def initialize_mutornadomon(tornado_app=None,
                            publisher=None,
                            publish_interval=None,
                            host_limit=None,
                            request_filter=None,
                            tracer_port=None,
                            **monitor_config):
    """Register mutornadomon to get Tornado request metrics"""
    if not publisher and not tornado_app:
        raise ValueError(
            'Must pass at least one of `publisher` and `tornado_app`')

    if publisher:
        external_interface = PublishExternalInterface(
            publisher, publish_interval=publish_interval)
    else:
        external_interface = HTTPEndpointExternalInterface(
            tornado_app, request_filter=request_filter, host_limit=host_limit)

    # Start collecting metrics and register endpoint with app
    monitor = MuTornadoMon(external_interface, **monitor_config)
    monitor.start()

    # If tracer_port is not provided then don't start the profiler
    if tracer_port is not None:
        profiler_ep = HTTPEndpointMuTornadoMonProfiler(request_filter)
        profiler_ep.start(monitor, tracer_port)

    if tornado_app:
        web_collector = WebCollector(monitor, tornado_app)
        web_collector.start()

    utilization_collector = UtilizationCollector(monitor)
    utilization_collector.start()

    return monitor
Ejemplo n.º 3
0
    def test_MuTornadoMon(self, pub_ext_iface_mock, mock_os, mock_ps):
        external_interface = pub_ext_iface_mock.return_value
        monitor = MuTornadoMon(external_interface)

        monitor.start()

        stat = 'test'
        val = 2

        # __COUNTERS[stat] = 2
        monitor.count(stat, val)

        # __COUNTERS[stat] = 3
        monitor.count(stat)
        self.assertEqual(monitor.metrics['counters'][stat], 3)


        monitor.kv(stat, 1)
        self.assertEqual(monitor.metrics['gauges'][stat], 1)

        # To make sure no exceptions are thrown
        monitor._cb()
        monitor._monkey_patch_ioloop_exceptions()

        monitor.__del__()
Ejemplo n.º 4
0
    def test_MuTornadoMon(self, pub_ext_iface_mock, mock_os, mock_ps):
        external_interface = pub_ext_iface_mock.return_value
        monitor = MuTornadoMon(external_interface)

        monitor.start()

        stat = 'test'
        val = 2

        # __COUNTERS[stat] = 2
        monitor.count(stat, val)

        # __COUNTERS[stat] = 3
        monitor.count(stat)
        self.assertEqual(monitor.metrics['counters'][stat], 3)

        monitor.kv(stat, 1)
        self.assertEqual(monitor.metrics['gauges'][stat], 1)

        # To make sure no exceptions are thrown
        monitor._cb()

        monitor.__del__()