Exemplo n.º 1
0
def rmq(args):
    host = config.get('rabbit_host')
    port = config.get('rabbit_port')
    try:
        cons = RMQConsumer(args.topic, host, port)
        for method, _, msg in cons.consume():
            print '{}: {}'.format(method.routing_key, msg)
    except RMQConnError:
        print 'No RabbitMQ host found.'
    except KeyboardInterrupt:
        cons.close_connection()
        print 'Connection closed'
Exemplo n.º 2
0
def rmq(args):
    host = config.get("rabbit_host")
    port = config.get("rabbit_port")
    try:
        cons = RMQConsumer(args.topic, host, port)
        for method, _, msg in cons.consume():
            print "{}: {}".format(method.routing_key, msg)
    except RMQConnError:
        print "No RabbitMQ host found."
    except KeyboardInterrupt:
        cons.close_connection()
        print "Connection closed"
Exemplo n.º 3
0
class TestCPUMemUsage(RMQTestCase):
    def onRabbitUp(self):
        self.rmq = RMQConsumer()

    def test_cpu_mem_are_percentages(self):
        cid = self._start_test_container(time=100)
        s = CPUMemoryPercSensor({"cid": cid})
        s.start()

        _, _, top = next(self.rmq.consume())

        vals = top["tot"].values()
        del top["tot"]
        for p in top.values():
            usages = p["usage"].values()
            vals.extend(usages)

        for v in vals:
            self.assertTrue(v >= 0 and v <= 100)

        s.kill()

    def test_tot_is_reasonable(self):
        cid = self._start_test_container(time=100)
        s = CPUMemoryPercSensor({"cid": cid})
        s.start()

        _, _, top = next(self.rmq.consume())

        real_tot = top["tot"]
        del top["tot"]

        expected_tot = {k: 0 for k in real_tot.keys()}
        for p in top.values():
            for k, v in p["usage"].items():
                expected_tot[k] += v

        self.assertEqual(real_tot, expected_tot)

        s.kill()
Exemplo n.º 4
0
class TestCPUMemUsage(RMQTestCase):
    def onRabbitUp(self):
        self.rmq = RMQConsumer()

    def test_cpu_mem_are_percentages(self):
        cid = self._start_test_container(time=100)
        s = CPUMemoryPercSensor({'cid': cid})
        s.start()

        _, _, top = next(self.rmq.consume())

        vals = top['tot'].values()
        del top['tot']
        for p in top.values():
            usages = p['usage'].values()
            vals.extend(usages)

        for v in vals:
            self.assertTrue(v >= 0 and v <= 100)

        s.kill()

    def test_tot_is_reasonable(self):
        cid = self._start_test_container(time=100)
        s = CPUMemoryPercSensor({'cid': cid})
        s.start()

        _, _, top = next(self.rmq.consume())

        real_tot = top['tot']
        del top['tot']

        expected_tot = {k: 0 for k in real_tot.keys()}
        for p in top.values():
            for k, v in p['usage'].items():
                expected_tot[k] += v

        self.assertEqual(real_tot, expected_tot)

        s.kill()
Exemplo n.º 5
0
class BaseRMQTestCase(RMQTestCase):
    def onRabbitUp(self):
        self.rmq = RMQConsumer()
        self.s = DummyRMQSensor({'cid': 'non-existent-container'})
        self.s.start()

    def onRabbitDown(self):
        self.s.kill()

    def test_values(self):
        n_msg = 10
        # push results to rabbit
        expected = []
        for i, d in enumerate(self.s.get_data()):
            expected.append(d)
            if i == n_msg - 1:
                break

        # get messages from rabbit
        real = [body for _, _, body in self.rmq.consume(n_msg)]
        self.assertEqual(expected, real)
Exemplo n.º 6
0
class BaseRMQTestCase(RMQTestCase):
    def onRabbitUp(self):
        self.rmq = RMQConsumer()
        self.s = DummyRMQSensor({'cid': 'non-existent-container'})
        self.s.start()

    def onRabbitDown(self):
        self.s.kill()

    def test_values(self):
        n_msg = 10
        # push results to rabbit
        expected = []
        for i, d in enumerate(self.s.get_data()):
            expected.append(d)
            if i == n_msg - 1:
                break

        # get messages from rabbit
        real = [body for _, _, body in self.rmq.consume(n_msg)]
        self.assertEqual(expected, real)
Exemplo n.º 7
0
 def onRabbitUp(self):
     self.rmq = RMQConsumer()
Exemplo n.º 8
0
 def onRabbitUp(self):
     self.rmq = RMQConsumer()
     self.s = DummyRMQSensor({'cid': 'non-existent-container'})
     self.s.start()
Exemplo n.º 9
0
 def onRabbitUp(self):
     self.rmq = RMQConsumer()
Exemplo n.º 10
0
 def onRabbitUp(self):
     self.rmq = RMQConsumer()
     self.s = DummyRMQSensor({'cid': 'non-existent-container'})
     self.s.start()