예제 #1
0
class TestExtendedMetrics(TestMetrics):
    def setUp(self):
        super(TestExtendedMetrics, self).setUp()
        self.metrics = ExtendedMetrics(self.connection, 'txstatsd.tests')

    def test_counter(self):
        """Test the increment and decrement operations."""
        self.metrics.increment('counter', 18)
        self.assertEqual(self.connection.data,
                         'txstatsd.tests.counter:18|c')
        self.metrics.decrement('counter', 9)
        self.assertEqual(self.connection.data,
                         'txstatsd.tests.counter:9|c')

    def test_sli(self):
        """Test SLI call."""
        self.metrics.sli('users', 100)
        self.assertEqual(self.connection.data,
                         'txstatsd.tests.users:100|sli')

        self.metrics.sli('users', 200, 2)
        self.assertEqual(self.connection.data,
                         'txstatsd.tests.users:200|sli|2')

        self.metrics.sli_error('users')
        self.assertEqual(self.connection.data,
                         'txstatsd.tests.users:error|sli')
예제 #2
0
 def setUp(self):
     """Set up test."""
     yield super(TestDelivery, self).setUp()
     self.mocker = Mocker()
     self.fake_reactor = DummyReactor()
     self.content = self.mocker.mock()
     self.node_owner_id = 1
     self.node_uuid = uuid.uuid4()
     self.node_hash = "hash:blah"
     self.owner_id = 0
     self.free_bytes = 0
     self.node_shard_id = 'shard1'
     self.node_volume_id = uuid.uuid4()
     self.content_node = self.mocker.mock()
     content_class = lambda _: self.content
     MetricsConnector.register_metrics("sli", instance=ExtendedMetrics())
     MetricsConnector.register_metrics("root", instance=ExtendedMetrics())
     MetricsConnector.register_metrics("user", instance=ExtendedMetrics())
     self.factory = StorageServerFactory(s3_host=None,
                                         s3_port=None,
                                         s3_key=None,
                                         s3_ssl=False,
                                         s3_secret=None,
                                         content_class=content_class,
                                         reactor=self.fake_reactor)
예제 #3
0
    def _metrics(cls, connection, namespace, async):
        """Returns a Metrics (configured with the statsd connection).

        Raises an Exception if missing statsd configuration.
        """

        if connection is None:
            connection = cls._realise_connection(async)
        return ExtendedMetrics(connection, namespace)
예제 #4
0
class TestExtendedMetrics(TestMetrics):
    def setUp(self):
        super(TestExtendedMetrics, self).setUp()
        self.metrics = ExtendedMetrics(self.connection, 'txstatsd.tests')

    def test_counter(self):
        """Test the increment and decrement operations."""
        self.metrics.increment('counter', 18)
        self.assertEqual(self.connection.data, b'txstatsd.tests.counter:18|c')
        self.metrics.decrement('counter', 9)
        self.assertEqual(self.connection.data, b'txstatsd.tests.counter:9|c')

    def test_sli(self):
        """Test SLI call."""
        self.metrics.sli('users', 100)
        self.assertEqual(self.connection.data, b'txstatsd.tests.users:100|sli')

        self.metrics.sli('users', 200, 2)
        self.assertEqual(self.connection.data,
                         b'txstatsd.tests.users:200|sli|2')

        self.metrics.sli_error('users')
        self.assertEqual(self.connection.data,
                         b'txstatsd.tests.users:error|sli')
예제 #5
0
def createService(options):
    """Create a txStatsD service."""
    from carbon.routers import ConsistentHashingRouter
    from carbon.client import CarbonClientManager
    from carbon.conf import settings

    settings.MAX_QUEUE_SIZE = options["max-queue-size"]
    settings.MAX_DATAPOINTS_PER_MESSAGE = options["max-datapoints-per-message"]

    root_service = MultiService()
    root_service.setName("statsd")

    prefix = options["prefix"]
    if prefix is None:
        prefix = "statsd"

    instance_name = options["instance-name"]
    if not instance_name:
        instance_name = platform.node()

    # initialize plugins
    plugin_metrics = []
    for plugin in getPlugins(IMetricFactory):
        plugin.configure(options)
        plugin_metrics.append(plugin)

    processor = None
    if options["dump-mode"]:
        # LoggingMessageProcessor supersedes
        #  any other processor class in "dump-mode"
        assert not hasattr(log, 'info')
        log.info = log.msg  # for compatibility with LMP logger interface
        processor = functools.partial(LoggingMessageProcessor, logger=log)

    if options["statsd-compliance"]:
        processor = (processor or MessageProcessor)(plugins=plugin_metrics)
        input_router = Router(processor, options['routing'], root_service)
        connection = InternalClient(input_router)
        metrics = Metrics(connection)
    else:
        processor = (processor or ConfigurableMessageProcessor)(
            message_prefix=prefix,
            internal_metrics_prefix=prefix + "." + instance_name + ".",
            plugins=plugin_metrics)
        input_router = Router(processor, options['routing'], root_service)
        connection = InternalClient(input_router)
        metrics = ExtendedMetrics(connection)

    if not options["carbon-cache-host"]:
        options["carbon-cache-host"].append("127.0.0.1")
    if not options["carbon-cache-port"]:
        options["carbon-cache-port"].append(2004)
    if not options["carbon-cache-name"]:
        options["carbon-cache-name"].append(None)

    reporting = ReportingService(instance_name)
    reporting.setServiceParent(root_service)

    reporting.schedule(report_client_manager_stats,
                       options["flush-interval"] / 1000, metrics.gauge)

    if options["report"] is not None:
        from txstatsd import process
        from twisted.internet import reactor

        reporting.schedule(process.report_reactor_stats(reactor), 60,
                           metrics.gauge)
        reports = [name.strip() for name in options["report"].split(",")]
        for report_name in reports:
            if report_name == "reactor":
                inspector = ReactorInspectorService(reactor,
                                                    metrics,
                                                    loop_time=0.05)
                inspector.setServiceParent(root_service)

            for reporter in getattr(process, "%s_STATS" % report_name.upper(),
                                    ()):
                reporting.schedule(reporter, 60, metrics.gauge)

    # XXX Make this configurable.
    router = ConsistentHashingRouter()
    carbon_client = CarbonClientManager(router)
    carbon_client.setServiceParent(root_service)

    for host, port, name in zip(options["carbon-cache-host"],
                                options["carbon-cache-port"],
                                options["carbon-cache-name"]):
        carbon_client.startClient((host, port, name))

    statsd_service = StatsDService(carbon_client, input_router,
                                   options["flush-interval"])
    statsd_service.setServiceParent(root_service)

    statsd_server_protocol = StatsDServerProtocol(
        input_router,
        monitor_message=options["monitor-message"],
        monitor_response=options["monitor-response"])

    listener = UDPServer(options["listen-port"], statsd_server_protocol)
    listener.setServiceParent(root_service)

    if options["listen-tcp-port"] is not None:
        statsd_tcp_server_factory = StatsDTCPServerFactory(
            input_router,
            monitor_message=options["monitor-message"],
            monitor_response=options["monitor-response"])

        listener = TCPServer(options["listen-tcp-port"],
                             statsd_tcp_server_factory)
        listener.setServiceParent(root_service)

    httpinfo_service = httpinfo.makeService(options, processor, statsd_service)
    httpinfo_service.setServiceParent(root_service)

    return root_service
예제 #6
0
 def setUp(self):
     super(TestExtendedMetrics, self).setUp()
     self.metrics = ExtendedMetrics(self.connection, 'txstatsd.tests')
예제 #7
0
 def setUp(self):
     super(TestExtendedMetrics, self).setUp()
     self.metrics = ExtendedMetrics(self.connection, 'txstatsd.tests')