Example #1
0
class JMXTestCase(unittest.TestCase):
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.environ['VOLATILE_DIR'], 'jmx_yaml')
        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def testCustomJMXMetric(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 20:
                raise Exception("No metrics were received in 20 seconds")

        metrics = self.reporter.metrics

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        self.assertEquals(len([t for t in metrics if t['metric'] == "my.metric.buf" and "instance:jmx_instance1" in t['tags']]), 2, metrics)
        self.assertTrue(len([t for t in metrics if 'type:ThreadPool' in t['tags'] and "instance:jmx_instance1" in t['tags'] and "jmx.catalina" in t['metric']]) > 8, metrics)
        self.assertTrue(len([t for t in metrics if "jvm." in t['metric'] and "instance:jmx_instance1" in t['tags']]) == 13, metrics)
Example #2
0
class TestTomcat(unittest.TestCase):
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()
        confd_path = os.path.join(os.path.dirname(__file__))

        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def test_tomcat_metrics(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 25:
                raise Exception("No metrics were received in 25 seconds")

        metrics = self.reporter.metrics

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        self.assertEquals(len([t for t in metrics if t['metric'] == "tomcat.threads.busy" and "instance:tomcat_instance" in t['tags']]), 2, metrics)
        self.assertEquals(len([t for t in metrics if t['metric'] == "tomcat.bytes_sent" and "instance:tomcat_instance" in t['tags']]), 0, metrics)
        self.assertTrue(len([t for t in metrics if "jvm." in t['metric'] and "instance:tomcat_instance" in t['tags']]) > 4, metrics)
Example #3
0
class JMXTestCase(unittest.TestCase):
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.path.dirname(__file__))

        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def testCustomJMXMetric(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 25:
                raise Exception("No metrics were received in 25 seconds")

        metrics = self.reporter.metrics

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        log.info([
            t for t in metrics if "cassandra." in t['metric']
            and "instance:cassandra_instance" in t['tags']
        ])
        log.info(metrics)
        log.info(
            len([
                t for t in metrics if "cassandra." in t['metric']
                and "instance:cassandra_instance" in t['tags']
            ]))
        log.info(
            len([
                t for t in metrics
                if "instance:cassandra_instance" in t['tags']
            ]))
        log.info(len([t for t in metrics if "cassandra." in t['metric']]))
        log.info(len(metrics))
        self.assertTrue(
            len([
                t for t in metrics if "cassandra." in t['metric']
                and "instance:cassandra_instance" in t['tags']
            ]) > 40, metrics)
Example #4
0
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.path.dirname(__file__))
        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()
Example #5
0
class TestKafka(unittest.TestCase):
    """Basic Test for kafka integration."""
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.path.dirname(__file__), 'resources/')

        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def testCustomJMXMetric(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 25:
                raise Exception("No metrics were received in 25 seconds")

        metrics = self.reporter.metrics
        # expected_tags = ['env:test', 'instance:kafka-172.17.0.1-9999', 'kafka:broker']

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        log.info(metrics)
        log.info(len(metrics))
        self.assertTrue(
            len([t for t in metrics if "jvm." in t['metric'] and "instance:kafka-172.17.0.1-9999" in t['tags']]) >= 13, metrics)
        self.assertTrue(
            len([t for t in metrics if "kafka.request." in t['metric'] and "instance:kafka-172.17.0.1-9999" in t['tags']]) == 12, metrics)
        self.assertTrue(
            len([t for t in metrics if "kafka.replication." in t['metric'] and "instance:kafka-172.17.0.1-9999" in t['tags']]) == 6, metrics)

        # CLIENT metrics.
        # kafka.producer.request_latency_avg
        self.assertTrue(
            len([t for t in metrics if "kafka.producer." in t['metric'] and "instance:kafka-172.17.0.1-7777" in t['tags']]) == 1, metrics)
        # kafka.consumer.fetch_rate, kafka.consumer.max_lag
        self.assertTrue(
            len([t for t in metrics if "kafka.consumer." in t['metric'] and "instance:kafka-172.17.0.1-7777" in t['tags']]) == 2, metrics)
Example #6
0
class JMXTestCase(unittest.TestCase):
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.environ['VOLATILE_DIR'], 'jmx_yaml')
        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def testCustomJMXMetric(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 20:
                raise Exception("No metrics were received in 20 seconds")

        metrics = self.reporter.metrics

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        self.assertEquals(
            len([
                t for t in metrics if t['metric'] == "my.metric.buf"
                and "instance:jmx_instance1" in t['tags']
            ]), 2, metrics)
        self.assertTrue(
            len([
                t for t in metrics
                if 'type:ThreadPool' in t['tags'] and "instance:jmx_instance1"
                in t['tags'] and "jmx.catalina" in t['metric']
            ]) > 8, metrics)
        self.assertTrue(
            len([
                t for t in metrics if "jvm." in t['metric']
                and "instance:jmx_instance1" in t['tags']
            ]) == 13, metrics)
Example #7
0
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.environ['VOLATILE_DIR'], 'jmx_yaml')
        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()
Example #8
0
    def test_start(self, select):
        select.select.side_effect = [KeyboardInterrupt, SystemExit]
        # TODO: v6 not supported on Travis
        # s1 = Server(mock.MagicMock(), '::1', '1234')
        # s1.start()
        # self.assertEqual(s1.socket.family, socket.AF_INET6)

        s2 = Server(mock.MagicMock(), '127.0.0.1', '2345')
        s2.start()
        self.assertEqual(s2.socket.family, socket.AF_INET6)

        s2 = Server(mock.MagicMock(), 'foo', '80')
        s2.start()
        self.assertFalse(s2.running)
Example #9
0
class JMXTestCase(unittest.TestCase):
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.path.dirname(__file__))

        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def testCustomJMXMetric(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 25:
                raise Exception("No metrics were received in 25 seconds")

        metrics = self.reporter.metrics

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        log.info([t for t in metrics if "cassandra." in t['metric'] and "instance:cassandra_instance" in t['tags']])
        log.info(metrics)
        log.info(len([t for t in metrics if "cassandra." in t['metric'] and "instance:cassandra_instance" in t['tags']]))
        log.info(len([t for t in metrics if "instance:cassandra_instance" in t['tags']]))
        log.info(len([t for t in metrics if "cassandra." in t['metric']]))
        log.info(len(metrics))
        self.assertTrue(len([t for t in metrics if "cassandra." in t['metric'] and "instance:cassandra_instance" in t['tags']]) > 40, metrics)
Example #10
0
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.path.dirname(__file__), 'resources/')

        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()
Example #11
0
    def test_start(self, select):
        select.select.side_effect = [KeyboardInterrupt, SystemExit]
        ipv6_test = False
        if _ipv6_available('::1', '1234'):
            ipv6_test = True
            s1 = Server(mock.MagicMock(), '::1', '1234')
            s1.start()
            self.assertEqual(s1.socket.family, socket.AF_INET6)

            original_so_rcvbuf = s1.socket.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)

        s2 = Server(mock.MagicMock(), '127.0.0.1', '2345', so_rcvbuf=1023)
        s2.start()
        self.assertEqual(s2.socket.family, socket.AF_INET6)

        if ipv6_test:
            self.assertNotEquals(original_so_rcvbuf, s2.socket.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))

        s2 = Server(mock.MagicMock(), 'foo', '80')
        s2.start()
        self.assertFalse(s2.running)
Example #12
0
    def test_init(self):
        s = Server(None, 'localhost', '1234')

        self.assertIsNone(s.sockaddr)
        self.assertIsNone(s.socket)
Example #13
0
    def test_start(self, select):
        select.select.side_effect = [KeyboardInterrupt, SystemExit]
        ipv6_test = False
        if _ipv6_available('::1', '1234'):
            ipv6_test = True
            s1 = Server(mock.MagicMock(), '::1', '1234')
            s1.start()
            self.assertEqual(s1.socket.family, socket.AF_INET6)

            original_so_rcvbuf = s1.socket.getsockopt(socket.SOL_SOCKET,
                                                      socket.SO_RCVBUF)

        s2 = Server(mock.MagicMock(), '127.0.0.1', '2345', so_rcvbuf=1023)
        s2.start()
        self.assertEqual(s2.socket.family, socket.AF_INET6)

        if ipv6_test:
            self.assertNotEquals(
                original_so_rcvbuf,
                s2.socket.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))

        s2 = Server(mock.MagicMock(), 'foo', '80')
        s2.start()
        self.assertFalse(s2.running)
Example #14
0
class TestKafka(unittest.TestCase):
    """Basic Test for kafka integration."""
    def setUp(self):
        aggregator = MetricsAggregator("test_host")
        self.server = Server(aggregator, "localhost", STATSD_PORT)
        self.reporter = DummyReporter(aggregator)

        self.t1 = threading.Thread(target=self.server.start)
        self.t1.start()

        confd_path = os.path.join(os.path.dirname(__file__), 'resources/')

        self.jmx_daemon = JMXFetch(confd_path, {'sdstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()

    def tearDown(self):
        self.server.stop()
        self.reporter.finished = True
        self.jmx_daemon.terminate()

    def testCustomJMXMetric(self):
        count = 0
        while self.reporter.metrics is None:
            time.sleep(1)
            count += 1
            if count > 25:
                raise Exception("No metrics were received in 25 seconds")

        metrics = self.reporter.metrics
        # expected_tags = ['env:test', 'instance:kafka-172.17.0.1-9999', 'kafka:broker']

        self.assertTrue(isinstance(metrics, ListType))
        self.assertTrue(len(metrics) > 0)
        log.info(metrics)
        log.info(len(metrics))
        self.assertTrue(
            len([
                t for t in metrics if "jvm." in t['metric']
                and "instance:kafka-172.17.0.1-9999" in t['tags']
            ]) >= 13, metrics)
        self.assertTrue(
            len([
                t for t in metrics if "kafka.request." in t['metric']
                and "instance:kafka-172.17.0.1-9999" in t['tags']
            ]) == 12, metrics)
        self.assertTrue(
            len([
                t for t in metrics if "kafka.replication." in t['metric']
                and "instance:kafka-172.17.0.1-9999" in t['tags']
            ]) == 6, metrics)

        # CLIENT metrics.
        # kafka.producer.request_latency_avg
        self.assertTrue(
            len([
                t for t in metrics if "kafka.producer." in t['metric']
                and "instance:kafka-172.17.0.1-7777" in t['tags']
            ]) == 1, metrics)
        # kafka.consumer.fetch_rate, kafka.consumer.max_lag
        self.assertTrue(
            len([
                t for t in metrics if "kafka.consumer." in t['metric']
                and "instance:kafka-172.17.0.1-7777" in t['tags']
            ]) == 2, metrics)