Example #1
0
    def _cleanup(self):
        plugin_model.collection.remove()
        counters_collection = plugin_model._get_counters_collection()
        counters_collection.remove()

        gauges_collection = plugin_model._get_gauges_data_collection()
        gauges_collection.remove()
Example #2
0
    def get_check_for_timestamp_test(self):

        self._cleanup()

        gauges_collection = plugin_model._get_gauges_data_collection()
        plugin = plugin_model.get_or_create(name='test1', server_id=self.server['_id'])
        plugin_with_error = plugin_model.get_or_create(name='error1', server_id=self.server['_id'])

        for i in range(0, 100):
            data = {'t': i, 'count.first': 2, 'count.second': 4, 'count.third': 5 }
            formated_data = flat_to_tree_dict_helper(data)
            formated_data['plugin_id'] = plugin['_id']
            formated_data['server_id'] = self.server_id

            gauges_collection.insert(formated_data)


        error_data = {'plugin_id': plugin_with_error['_id'], 'server_id': self.server_id,
        't': 10, 'error': 'Argghh'}
        error_collection = plugin_model._get_error_collection()
        error_collection.insert(error_data)

        result = plugin_model.get_check_for_timestamp(self.server, 10)


        for r in result:
            assert r['name'] in ['test1', 'error1']

        self._cleanup()
Example #3
0
    def _cleanup(self):
        plugin_model.collection.remove()
        counters_collection = plugin_model._get_counters_collection()
        counters_collection.remove()

        gauges_collection = plugin_model._get_gauges_data_collection()
        gauges_collection.remove()
Example #4
0
    def save_gauges_test(self):
        self._cleanup()


        expires_at = datetime.utcnow()+timedelta(hours=24)


        plugin = plugin_model.get_or_create(name='test1', server_id=self.server['_id'])
        gauge_data = {
            u'performance.cpu_load': 1.08719, u'performance.busy_workers': 117.0,
            u'performance.idle_workers': 523.0, u'net.bytes': 86855934115.0,
            u'requests.per.second': 140.7, u'net.hits': 35534902.0
        }

        plugin_model.save_gauges(data=gauge_data, plugin=plugin, time=1, expires_at=expires_at)

        collection = plugin_model._get_gauges_data_collection()

        gauges = plugin_model.get_gauges_cursor(plugin=plugin)

        gauges_dict = {}
        for g in gauges:
            gauges_dict[str(g['_id'])] = g['name']


        for r in collection.find():
            gauge_id = str(r['gauge_id'])

            gauge_name = gauges_dict[gauge_id]
            assert gauge_name in ['net', 'performance', 'requests']
            self.assertTrue(r['t'], int)
            self.assertEqual(r['expires_at'].date(), expires_at.date())

            if gauge_name == 'net':
                self.assertCountEqual(r.keys(), [u't', u'hits', u'bytes', u'gauge_id', u'_id', 'expires_at'])

                self.assertEqual(r['hits'], 35534902.0)
                self.assertEqual(r['bytes'], 86855934115.0)

            elif gauge_name == 'performance':

                self.assertCountEqual(r.keys(), [u't', u'cpu_load', u'busy_workers', u'idle_workers', u'gauge_id', u'_id', 'expires_at'])

                self.assertEqual(r['cpu_load'],  1.08719)
                self.assertEqual(r['busy_workers'], 117.0)
                self.assertEqual(r['idle_workers'], 523.0)

            elif gauge_name == 'requests':

                self.assertCountEqual(r.keys(), [u't', u'per_second', u'gauge_id', u'_id', 'expires_at'])

                self.assertEqual(r['per_second'],  140.7)


        self._cleanup()
Example #5
0
    def get_gauge_data_test(self):
        self._cleanup()

        plugin = plugin_model.get_or_create(name='test1',
                                            server_id=self.server['_id'])

        gauges_collection = plugin_model._get_gauges_data_collection()

        for i in range(0, 100):
            data = {
                't': i,
                'count.first': 11,
                'count.second': 22,
                'count.third': 33
            }
            plugin_model.save_gauges(data=data, plugin=plugin, time=i)

        gauge = plugin_model.get_gauge_by_name(name='count', plugin=plugin)

        result = plugin_model.get_gauge_data_after(timestamp=0,
                                                   enddate=29,
                                                   gauge=gauge)

        eq_(len(result), 3)  # first, second, third

        for i in result:
            assert i['name'] in ['first', 'second', 'third']
            assert len(i['data']) == 30

            for point in i['data']:
                assert point['y'] in [33, 22, 11]

        self._cleanup()

        for i in range(0, 100):
            data = {'t': i, 'count': 2}
            plugin_model.save_gauges(data=data, plugin=plugin, time=i)

        result = plugin_model.get_gauge_data_after(timestamp=0,
                                                   enddate=29,
                                                   gauge=gauge)

        eq_(len(result), 1)  # count

        count = result[0]

        eq_(count['name'], 'value')  # Single value
        eq_(len(count['data']), 30)

        self._cleanup()
Example #6
0
    def get_gauge_data_test(self):
        self._cleanup()


        plugin = plugin_model.get_or_create(name='test1', server_id=self.server['_id'])


        gauges_collection = plugin_model._get_gauges_data_collection()

        for i in range(0, 100):
            data = {'t': i, 'count.first': 11, 'count.second': 22, 'count.third': 33 }
            plugin_model.save_gauges(data=data, plugin=plugin, time=i)

        gauge = plugin_model.get_gauge_by_name(name='count', plugin=plugin)


        result = plugin_model.get_gauge_data_after(timestamp=0, enddate=29, gauge=gauge)

        eq_(len(result), 3)   # first, second, third


        for i in result:
            assert i['name'] in ['first', 'second', 'third']
            assert len(i['data']) == 30

            for point in i['data']:
                assert point['y'] in [33, 22, 11]


        self._cleanup()

        for i in range(0, 100):
            data = {'t': i, 'count': 2}
            plugin_model.save_gauges(data=data, plugin=plugin, time=i)

        result = plugin_model.get_gauge_data_after(timestamp=0, enddate=29,  gauge=gauge)

        eq_(len(result),1 )  # count

        count = result[0]

        eq_(count['name'], 'value') # Single value
        eq_(len(count['data']), 30)



        self._cleanup()
Example #7
0
    def delete_gauges_test(self):
        self._cleanup()

        plugin = plugin_model.get_or_create(name='test1', server_id=self.server['_id'])
        gauge_data = {u'performance.cpu_load': 1.08719, u'performance.busy_workers': 117.0,}

        for i in range(0, 10):
            plugin_model.save_gauges(data=gauge_data, plugin=plugin)

        collection = plugin_model._get_gauges_data_collection()

        result = collection.find().count()
        eq_(result, 10)

        plugin_model.delete_gauges(plugin=plugin)
        result = collection.find().count()


        eq_(result, 0)

        self._cleanup()
Example #8
0
    def get_check_for_timestamp_test(self):

        self._cleanup()

        gauges_collection = plugin_model._get_gauges_data_collection()
        plugin = plugin_model.get_or_create(name='test1',
                                            server_id=self.server['_id'])
        plugin_with_error = plugin_model.get_or_create(
            name='error1', server_id=self.server['_id'])

        for i in range(0, 100):
            data = {
                't': i,
                'count.first': 2,
                'count.second': 4,
                'count.third': 5
            }
            formated_data = flat_to_tree_dict_helper(data)
            formated_data['plugin_id'] = plugin['_id']
            formated_data['server_id'] = self.server_id

            gauges_collection.insert(formated_data)

        error_data = {
            'plugin_id': plugin_with_error['_id'],
            'server_id': self.server_id,
            't': 10,
            'error': 'Argghh'
        }
        error_collection = plugin_model._get_error_collection()
        error_collection.insert(error_data)

        result = plugin_model.get_check_for_timestamp(self.server, 10)

        for r in result:
            assert r['name'] in ['test1', 'error1']

        self._cleanup()
Example #9
0
    def delete_gauges_test(self):
        self._cleanup()

        plugin = plugin_model.get_or_create(name='test1',
                                            server_id=self.server['_id'])
        gauge_data = {
            u'performance.cpu_load': 1.08719,
            u'performance.busy_workers': 117.0,
        }

        for i in range(0, 10):
            plugin_model.save_gauges(data=gauge_data, plugin=plugin)

        collection = plugin_model._get_gauges_data_collection()

        result = collection.find().count()
        eq_(result, 10)

        plugin_model.delete_gauges(plugin=plugin)
        result = collection.find().count()

        eq_(result, 0)

        self._cleanup()
Example #10
0
    def save_gauges_test(self):
        self._cleanup()

        expires_at = datetime.utcnow() + timedelta(hours=24)

        plugin = plugin_model.get_or_create(name='test1',
                                            server_id=self.server['_id'])
        gauge_data = {
            u'performance.cpu_load': 1.08719,
            u'performance.busy_workers': 117.0,
            u'performance.idle_workers': 523.0,
            u'net.bytes': 86855934115.0,
            u'requests.per.second': 140.7,
            u'net.hits': 35534902.0
        }

        plugin_model.save_gauges(data=gauge_data,
                                 plugin=plugin,
                                 time=1,
                                 expires_at=expires_at)

        collection = plugin_model._get_gauges_data_collection()

        gauges = plugin_model.get_gauges_cursor(plugin=plugin)

        gauges_dict = {}
        for g in gauges:
            gauges_dict[str(g['_id'])] = g['name']

        for r in collection.find():
            gauge_id = str(r['gauge_id'])

            gauge_name = gauges_dict[gauge_id]
            assert gauge_name in ['net', 'performance', 'requests']
            self.assertTrue(r['t'], int)
            self.assertEqual(r['expires_at'].date(), expires_at.date())

            if gauge_name == 'net':
                self.assertCountEqual(r.keys(), [
                    u't', u'hits', u'bytes', u'gauge_id', u'_id', 'expires_at'
                ])

                self.assertEqual(r['hits'], 35534902.0)
                self.assertEqual(r['bytes'], 86855934115.0)

            elif gauge_name == 'performance':

                self.assertCountEqual(r.keys(), [
                    u't', u'cpu_load', u'busy_workers', u'idle_workers',
                    u'gauge_id', u'_id', 'expires_at'
                ])

                self.assertEqual(r['cpu_load'], 1.08719)
                self.assertEqual(r['busy_workers'], 117.0)
                self.assertEqual(r['idle_workers'], 523.0)

            elif gauge_name == 'requests':

                self.assertCountEqual(
                    r.keys(),
                    [u't', u'per_second', u'gauge_id', u'_id', 'expires_at'])

                self.assertEqual(r['per_second'], 140.7)

        self._cleanup()
Example #11
0
    def get_gauges_data_collection_test(self):
        self._cleanup()
        result = plugin_model._get_gauges_data_collection()

        eq_(result.name, "plugin_gauges_data")
Example #12
0
    def get_gauges_data_collection_test(self):
        self._cleanup()
        result = plugin_model._get_gauges_data_collection()

        eq_(result.name, "plugin_gauges_data")