Esempio n. 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 = Fixtures.directory()
        self.jmx_daemon = JMXFetch(confd_path, {'dogstatsd_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 testTomcatMetrics(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) > 8, metrics)
        self.assertEquals(len([t for t in metrics if 'instance:solr_instance' in t['tags'] and t['metric'] == "jvm.thread_count"]), 1, metrics)
        self.assertTrue(len([t for t in metrics if "jvm." in t['metric'] and 'instance:solr_instance' in t['tags']]) > 4, metrics)
        self.assertTrue(len([t for t in metrics if "solr." in t['metric'] and 'instance:solr_instance' in t['tags']]) > 4, metrics)
Esempio n. 2
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, {'dogstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()
Esempio n. 3
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 = Fixtures.directory()
        self.jmx_daemon = JMXFetch(confd_path, {'dogstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()
Esempio n. 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__), 'ci/resources/')

        self.jmx_daemon = JMXFetch(confd_path, {'dogstatsd_port': STATSD_PORT})
        self.t2 = threading.Thread(target=self.jmx_daemon.run)
        self.t2.start()
Esempio n. 5
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, {'dogstatsd_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)
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__), 'ci')
        # confd_path = os.path.join(os.environ['VOLATILE_DIR'], 'jmx_yaml')

        self.jmx_daemon = JMXFetch(confd_path, {'dogstatsd_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)
Esempio n. 7
0
    def test_init(self, nh):
        nh.return_value = 'foo'

        s = Server(None, 'localhost', '1234')
        nh.assertCalledOnceWith('localhost', 1234)

        self.assertEqual(s.sockaddr, 'foo')
        self.assertIsNone(s.socket)
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__), 'ci')

        self.jmx_daemon = JMXFetch(confd_path, {'dogstatsd_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)
Esempio n. 9
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__), 'ci/resources/')

        self.jmx_daemon = JMXFetch(confd_path, {'dogstatsd_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)
Esempio n. 10
0
    def test_start(self, select):
        select.select.side_effect = [KeyboardInterrupt, SystemExit]
        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)
Esempio n. 11
0
    def test_init(self):
        s = Server(None, 'localhost', '1234')

        self.assertIsNone(s.sockaddr)
        self.assertIsNone(s.socket)
Esempio n. 12
0
    def test_start(self, select):
        select.select.side_effect = [KeyboardInterrupt, SystemExit]
        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)
        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)