Files
monasca-agent/tests/test_cassandra_jmx.py
Tim Kuhlman 19cd1c053e Remove emit_time from the collector and put it into the forwarder.
Fixed the service dimension for api checks on various openstack services
so that it matches that of the other service checks, allowing for it to
be grouped together.

Modified the config so a config in the working dir can be used this is
helpful for testing. Additionally I fixed up few tests and removed
some no longer used, there is a lot of work with test left unfinished

Change-Id: Ic5b127db41c174735f1436bb511f00e271274cb0
2015-02-04 14:54:00 -07:00

75 lines
2.1 KiB
Python

import unittest
import time
import threading
import os
from nose.plugins.skip import SkipTest
from monasca_agent.common.aggregator import MetricsAggregator
from monasca_agent.statsd import Server
from monasca_agent.common.config import get_logging_config
from monasca_agent.collector.jmxfetch import JMXFetch
STATSD_PORT = 8121
class DummyReporter(threading.Thread):
def __init__(self, metrics_aggregator):
threading.Thread.__init__(self)
self.finished = threading.Event()
self.metrics_aggregator = metrics_aggregator
self.interval = 10
self.metrics = None
self.finished = False
self.start()
def run(self):
while not self.finished:
time.sleep(self.interval)
self.flush()
def flush(self):
metrics = self.metrics_aggregator.flush()
if metrics:
self.metrics = metrics
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.realpath(os.path.join(os.path.abspath(__file__), "..", "jmx_yamls"))
JMXFetch.init(confd_path, {'dogstatsd_port': STATSD_PORT}, get_logging_config(), 15)
def tearDown(self):
self.server.stop()
self.reporter.finished = True
JMXFetch.stop()
def testCustomJMXMetric(self):
raise SkipTest('Requires JMX be setup')
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, list))
self.assertTrue(len(metrics) > 0)
self.assertTrue(len([t for t in metrics if "cassandra.db." in t[
'metric'] and "instance:cassandra_instance" in t['dimensions']]) > 40, metrics)
if __name__ == "__main__":
unittest.main()