コード例 #1
0
 def test_logs(self):
     config = {'logging': True, 'metrics': LocalClient.AVAILABLE_METRICS}
     obj = LocalClient(ROOT_LOGGER, 'label', config, EngineEmul())
     obj.connect()
     obj.get_data()
     self.assertIn('logging', obj.config)
     self.assertIsNotNone(obj.monitoring_logs)
コード例 #2
0
ファイル: test_monitoring.py プロジェクト: yue530tom/taurus
 def test_local_without_engine(self):
     config = {'metrics': ['cpu']}
     obj = LocalClient(ROOT_LOGGER, 'label', config, EngineEmul())
     obj.connect()
     data = obj.get_data()
     self.assertEqual(obj.interval, obj.engine.check_interval)
     self.assertTrue(all('source' in item.keys() and 'ts' in item.keys() for item in data))
コード例 #3
0
ファイル: test_monitoring.py プロジェクト: yue530tom/taurus
 def test_local_with_engine(self):
     config = {'interval': '5m', 'metrics': ['cpu', 'engine-loop']}
     obj = LocalClient(ROOT_LOGGER, 'label', config, EngineEmul())
     obj.connect()
     data = obj.get_data()
     self.assertTrue(300, obj.interval)
     self.assertTrue(all('source' in item and 'ts' in item for item in data))
コード例 #4
0
 def test_local_without_engine(self):
     config = {'metrics': ['cpu']}
     obj = LocalClient(logging.getLogger(''), 'label', config)
     obj.connect()
     data = obj.get_data()
     self.assertTrue(all('source' in item.keys() and 'ts' in item.keys() for item in data))
     return data
コード例 #5
0
ファイル: test_monitoring.py プロジェクト: keithmork/taurus
 def test_local_with_engine(self):
     config = {'interval': '5m', 'metrics': ['cpu', 'engine-loop']}
     obj = LocalClient(logging.getLogger(''), 'label', config, EngineEmul())
     obj.connect()
     data = obj.get_data()
     self.assertTrue(300, obj.interval)
     self.assertTrue(all('source' in item and 'ts' in item for item in data))
コード例 #6
0
ファイル: test_monitoring.py プロジェクト: keithmork/taurus
 def test_local_without_engine(self):
     config = {'metrics': ['cpu']}
     obj = LocalClient(logging.getLogger(''), 'label', config, EngineEmul())
     obj.connect()
     data = obj.get_data()
     self.assertEqual(obj.interval, obj.engine.check_interval)
     self.assertTrue(all('source' in item.keys() and 'ts' in item.keys() for item in data))
コード例 #7
0
ファイル: test_monitoring.py プロジェクト: yue530tom/taurus
 def test_logs(self):
     config = {'logging': True, 'metrics': ['bytes-sent', 'mem', 'cpu']}
     obj = LocalClient(ROOT_LOGGER, 'label', config, EngineEmul())
     obj.connect()
     patch = obj._get_resource_stats
     obj._get_resource_stats = lambda: {'mem': '4', 'bytes-sent': '2', 'cpu': '3'}
     try:
         obj.get_data()
     finally:
         obj._get_resource_stats = patch
     self.assertIn('logging', obj.config)
     self.assertEqual(['bytes-sent', 'cpu', 'mem'], sorted(obj.config['metrics']))
     self.assertIsNotNone(obj.logs_file)
     with open(obj.logs_file) as monitoring_logs:
         logs_reader = csv.reader(monitoring_logs)
         logs_reader = list(logs_reader)
     self.assertEqual(['ts', 'bytes-sent', 'cpu', 'mem'], logs_reader[0])
     self.assertEqual(['2', '3', '4'], logs_reader[1][1:])
コード例 #8
0
 def test_all_metrics(self):
     config = {'interval': '1m', 'metrics': LocalClient.AVAILABLE_METRICS}
     obj = LocalClient(ROOT_LOGGER, 'label', config, EngineEmul())
     obj.connect()
     self.assertEqual(60, obj.interval)
     data = obj.get_data()
     for item in data:
         metrics = set(item.keys()) - {'ts', 'source'}
         self.assertEqual(1, len(metrics))
         self.assertIn(metrics.pop(), LocalClient.AVAILABLE_METRICS)
     self.assertEqual(len(data), len(LocalClient.AVAILABLE_METRICS))
コード例 #9
0
ファイル: test_monitoring.py プロジェクト: keithmork/taurus
 def test_all_metrics(self):
     config = {'interval': '1m', 'metrics': LocalClient.AVAILABLE_METRICS}
     obj = LocalClient(logging.getLogger(''), 'label', config, EngineEmul())
     obj.connect()
     self.assertEqual(60, obj.interval)
     data = obj.get_data()
     for item in data:
         metrics = set(item.keys()) - {'ts', 'source'}
         self.assertEqual(1, len(metrics))
         self.assertIn(metrics.pop(), LocalClient.AVAILABLE_METRICS)
     self.assertEqual(len(data), len(LocalClient.AVAILABLE_METRICS))
コード例 #10
0
    def test_multiple_local_monitorings_cpu(self):
        # psutil.cpu_percent() has interesting semantics.
        # It will often return 0.0 , 50.0 or 100.0 if called too frequently,
        # which turns out to be the case when multiple LocalClient objects are used.
        config = {'metrics': ['cpu']}
        client1 = LocalClient(logging.getLogger(''), 'label', config)
        client2 = LocalClient(logging.getLogger(''), 'label', config)

        client1.connect()
        client2.connect()

        self.assertIsInstance(client1.monitor, LocalMonitor)
        self.assertIsInstance(client2.monitor, LocalMonitor)
        self.assertIs(client1.monitor, client2.monitor)

        data1 = client1.get_data()
        data2 = client2.get_data()
        for item1, item2 in zip(data1, data2):
            self.assertNotEqual(item1['cpu'], 0)
            self.assertNotEqual(item2['cpu'], 0)
            self.assertEqual(item1['cpu'], item2['cpu'])