Exemple #1
0
def test_statsd_monitor_conversion():
    """
    Test conversion
    """
    with Agent.run("""
monitors:
  - type: statsd
    listenPort: 0
    converters:
    - pattern: 'cluster.cds_{traffic}_{mesh}_{service}-vn_{}.{action}'
      metricName: '{traffic}.{action}'
""") as agent:
        port = get_statsd_port(agent)

        assert wait_for(p(udp_port_open_locally_netstat,
                          port)), "statsd port never opened!"
        send_udp_message(
            "localhost", port,
            "cluster.cds_egress_ecommerce-demo-mesh_gateway-vn_tcp_8080.update_success:8|c"
        )

        assert wait_for(
            p(
                has_datapoint,
                agent.fake_services,
                metric_name="egress.update_success",
                dimensions={
                    "traffic": "egress",
                    "mesh": "ecommerce-demo-mesh",
                    "service": "gateway",
                    "action": "update_success",
                },
            )), "Didn't get metric"
def test_collectd_dogstatsd():
    with fake_backend.start() as backend:
        # configure the dogstatsd plugin to send to fake ingest
        config = DOGSTATSD_CONFIG.substitute(ingestEndpoint=backend.ingest_url)

        # start the agent with the dogstatsd plugin config
        with run_agent_with_fake_backend(config,
                                         backend) as [get_output, _, _, _]:
            # wait until the dogstatsd plugin logs the address and port it is listening on
            assert wait_for(
                p(regex_search_matches_output, get_output,
                  DOGSTATSD_RE.search))

            # scrape the host and port that the dogstatsd plugin is listening on
            regex_results = DOGSTATSD_RE.search(get_output())
            host = regex_results.groups()[1]
            port = int(regex_results.groups()[2])

            # wait for dogstatsd port to open
            assert wait_for(p(udp_port_open_locally, port))

            # send datapoints to the dogstatsd listener
            for _ in range(0, 10):
                send_udp_message(
                    host, port,
                    "dogstatsd.test.metric:55555|g|#dimension1:value1,dimension2:value2"
                )
                time.sleep(1)

            # wait for fake ingest to receive the dogstatsd metrics
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "dogstatsd.test.metric"))
Exemple #3
0
def test_statsd_monitor_prefix():
    """
    Test metric prefix
    """
    with Agent.run("""
monitors:
  - type: statsd
    listenPort: 0
    metricPrefix: statsd.appmesh
""") as agent:
        port = get_statsd_port(agent)

        assert wait_for(p(udp_port_open_locally_netstat,
                          port)), "statsd port never opened!"
        send_udp_message(
            "localhost",
            port,
            "statsd.appmesh.cluster.cds_egress_ecommerce-demo-mesh_gateway-vn_tcp_8080.update_success:8|c",
        )

        assert wait_for(
            p(
                has_datapoint_with_metric_name,
                agent.fake_services,
                "cluster.cds_egress_ecommerce-demo-mesh_gateway-vn_tcp_8080.update_success",
            )), "Didn't get statsd.test metric"
Exemple #4
0
def test_appmesh_monitor():
    """
    Test conversion
    """
    with Agent.run("""
monitors:
  - type: appmesh
    listenPort: 0
""") as agent:
        port = get_statsd_port(agent)

        assert wait_for(p(udp_port_open_locally,
                          port)), "statsd port never opened!"
        send_udp_message(
            "localhost",
            port,
            "cluster.cds_egress_ecommerce-demo-mesh_gateway-vn_tcp_8080.upstream_cx_rx_bytes_total:8|c",
        )

        assert wait_for(
            p(
                has_datapoint,
                agent.fake_services,
                metric_name="upstream_cx_rx_bytes_total",
                dimensions={
                    "traffic": "egress",
                    "mesh": "ecommerce-demo-mesh",
                    "service": "gateway",
                    "action": "upstream_cx_rx_bytes_total",
                },
            )), "Didn't get metric"
Exemple #5
0
def test_statsd_monitor():
    """
    Test basic functionality
    """
    with Agent.run("""
monitors:
  - type: statsd
    listenPort: 8111
""") as agent:
        port = get_statsd_port(agent)

        assert wait_for(p(udp_port_open_locally_netstat,
                          port)), "statsd port never opened!"
        send_udp_message("localhost", port, "statsd.test:1|g")

        assert wait_for(
            p(has_datapoint_with_metric_name, agent.fake_services,
              "statsd.test")), "Didn't get statsd.test metric"
Exemple #6
0
def test_statsd_monitor():
    """
    Test basic functionality
    """
    with run_agent(
        """
monitors:
  - type: collectd/statsd
    listenAddress: localhost
    listenPort: 8125
    counterSum: true
"""
    ) as [backend, _, _]:
        assert wait_for(p(udp_port_open_locally, 8125)), "statsd port never opened!"
        send_udp_message("localhost", 8125, "statsd.[foo=bar,dim=val]test:1|g")

        assert wait_for(p(has_datapoint_with_dim, backend, "plugin", "statsd")), "Didn't get statsd datapoints"
        assert wait_for(
            p(has_datapoint_with_metric_name, backend, "gauge.statsd.test")
        ), "Didn't get statsd.test metric"
        assert wait_for(p(has_datapoint_with_dim, backend, "foo", "bar")), "Didn't get foo dimension"
def test_telegraf_statsd():
    with Agent.run(MONITOR_CONFIG) as agent:
        # wait until the statsd plugin logs the address and port it is listening on
        assert wait_for(
            p(regex_search_matches_output, agent.get_output, STATSD_RE.search))

        # scrape the host and port that the statsd plugin is listening on
        regex_results = STATSD_RE.search(agent.output)

        host = regex_results.groups()[1]
        port = int(regex_results.groups()[2])

        # send datapoints to the statsd listener
        for _ in range(0, 10):
            send_udp_message(
                host, port,
                "statsd.test.metric:55555|g|#dimension1:value1,dimension2:value2"
            )
            time.sleep(1)

        # wait for fake ingest to receive the statsd metrics
        assert wait_for(
            p(has_datapoint_with_metric_name, agent.fake_services,
              "statsd.test.metric"))
        assert wait_for(
            p(has_datapoint_with_dim, agent.fake_services, "dimension1",
              "value1")), "datapoint didn't have datadog tag"

        # send datapoints to the statsd listener
        for _ in range(0, 10):
            send_udp_message(
                host, port,
                "dogstatsd.test.metric:55555|g|#dimension1:,dimension2:value2")
            time.sleep(1)

        assert wait_for(
            p(has_datapoint_with_metric_name, agent.fake_services,
              "dogstatsd.test.metric")
        ), "didn't report metric with valueless datadog tag"