def setUp(self): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte' }) self.collector = MemoryCgroupCollector(config, None)
def test_should_work_with_real_data(self, publish_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() self.assertPublishedMany( publish_mock, { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, })
class TestMemoryCgroupCollector(CollectorTestCase): def setUp(self): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': ['megabyte','byte'] }) self.collector = MemoryCgroupCollector(config, None) def test_import(self): self.assertTrue(MemoryCgroupCollector) @patch('os.walk', Mock(return_value=iter(fixtures))) @patch.object(Collector, 'publish') def test_should_open_all_cpuacct_stat(self, publish_mock): open_mock = mock_open() with patch('__builtin__.open', open_mock): self.collector.collect() open_mock.assert_any_call( fixtures_path + 'lxc/testcontainer/memory.stat') open_mock.assert_any_call(fixtures_path + 'lxc/memory.stat') open_mock.assert_any_call(fixtures_path + 'memory.stat') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): MemoryCgroupCollector.MEMORY_PATH = fixtures_path self.collector.collect() self.assertPublishedMany(publish_mock, { 'lxc.testcontainer.cache': 2**20, 'lxc.testcontainer.rss': 2**20, 'lxc.testcontainer.swap': 2**20, 'lxc.testcontainer.limit': 2**20, 'lxc.cache': 2**20, 'lxc.rss': 2**20, 'lxc.swap': 2**20, 'lxc.limit': 2**20, 'system.cache': 2**20, 'system.rss': 2**20, 'system.swap': 2**20, 'system.limit': 2**20, 'lxc.testcontainer.megabyte_cache': 1, 'lxc.testcontainer.megabyte_rss': 1, 'lxc.testcontainer.megabyte_swap': 1, 'lxc.testcontainer.megabyte_limit': 1, 'lxc.megabyte_cache': 1, 'lxc.megabyte_rss': 1, 'lxc.megabyte_swap': 1, 'lxc.megabyte_limit': 1, 'system.megabyte_cache': 1, 'system.megabyte_rss': 1, 'system.megabyte_swap': 1, 'system.megabyte_limit': 1, })
def test_should_open_all_memory_stat(self, publish_mock, open_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte' }) self.collector = MemoryCgroupCollector(config, None) open_mock.side_effect = lambda x: StringIO('') self.collector.collect() open_mock.assert_any_call(fixtures_path + 'lxc/testcontainer/memory.stat') open_mock.assert_any_call(fixtures_path + 'lxc/memory.stat') open_mock.assert_any_call(fixtures_path + 'memory.stat')
def test_should_work_with_real_data(self, publish_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() self.assertPublishedMany(publish_mock, { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, })
def test_should_not_include_filtered_metrics(self, publish_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path, 'skip': 'test\w+ner', }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() should_be_published = { 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, } should_not_be_published = { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, } [self.assertPublished(publish_mock, k, v) for k, v in should_be_published.iteritems()] [self.assertUnpublished(publish_mock, k, v) for k, v in should_not_be_published.iteritems()]
def test_should_not_include_filtered_metrics(self, publish_mock): config = get_collector_config( 'MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path, 'skip': 'test\w+ner', }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() should_be_published = { 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, } should_not_be_published = { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, } [ self.assertPublished(publish_mock, k, v) for k, v in should_be_published.iteritems() ] [ self.assertUnpublished(publish_mock, k, v) for k, v in should_not_be_published.iteritems() ]
class TestMemoryCgroupCollector(CollectorTestCase): def setUp(self): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte' }) self.collector = MemoryCgroupCollector(config, None) def test_import(self): self.assertTrue(MemoryCgroupCollector) @patch('__builtin__.open') @patch('os.walk', Mock(return_value=iter(fixtures))) @patch.object(Collector, 'publish') def test_should_open_all_cpuacct_stat(self, publish_mock, open_mock): open_mock.side_effect = lambda x: StringIO('') self.collector.collect() open_mock.assert_any_call(fixtures_path + 'lxc/testcontainer/memory.stat') open_mock.assert_any_call(fixtures_path + 'lxc/memory.stat') open_mock.assert_any_call(fixtures_path + 'memory.stat') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): MemoryCgroupCollector.MEMORY_PATH = fixtures_path self.collector.collect() self.assertPublishedMany( publish_mock, { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, })
def test_should_open_all_memory_stat(self, publish_mock, open_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte' }) self.collector = MemoryCgroupCollector(config, None) open_mock.side_effect = lambda x: StringIO('') self.collector.collect() open_mock.assert_any_call( fixtures_path + 'lxc/testcontainer/memory.stat') open_mock.assert_any_call(fixtures_path + 'lxc/memory.stat') open_mock.assert_any_call(fixtures_path + 'memory.stat')
class TestMemoryCgroupCollector(CollectorTestCase): def test_import(self): self.assertTrue(MemoryCgroupCollector) @patch('__builtin__.open') @patch('os.walk', Mock(return_value=iter(fixtures))) @patch.object(Collector, 'publish') def test_should_open_all_memory_stat(self, publish_mock, open_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte' }) self.collector = MemoryCgroupCollector(config, None) open_mock.side_effect = lambda x: StringIO('') self.collector.collect() open_mock.assert_any_call(fixtures_path + 'lxc/testcontainer/memory.stat') open_mock.assert_any_call(fixtures_path + 'lxc/memory.stat') open_mock.assert_any_call(fixtures_path + 'memory.stat') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() self.assertPublishedMany( publish_mock, { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, }) @patch.object(Collector, 'publish') def test_should_not_include_filtered_metrics(self, publish_mock): config = get_collector_config( 'MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path, 'skip': 'test\w+ner', }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() should_be_published = { 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, } should_not_be_published = { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, } [ self.assertPublished(publish_mock, k, v) for k, v in should_be_published.iteritems() ] [ self.assertUnpublished(publish_mock, k, v) for k, v in should_not_be_published.iteritems() ]
class TestMemoryCgroupCollector(CollectorTestCase): def test_import(self): self.assertTrue(MemoryCgroupCollector) @patch('__builtin__.open') @patch('os.walk', Mock(return_value=iter(fixtures))) @patch.object(Collector, 'publish') def test_should_open_all_memory_stat(self, publish_mock, open_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte' }) self.collector = MemoryCgroupCollector(config, None) open_mock.side_effect = lambda x: StringIO('') self.collector.collect() open_mock.assert_any_call( fixtures_path + 'lxc/testcontainer/memory.stat') open_mock.assert_any_call(fixtures_path + 'lxc/memory.stat') open_mock.assert_any_call(fixtures_path + 'memory.stat') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() self.assertPublishedMany(publish_mock, { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, }) @patch.object(Collector, 'publish') def test_should_not_include_filtered_metrics(self, publish_mock): config = get_collector_config('MemoryCgroupCollector', { 'interval': 10, 'byte_unit': 'megabyte', 'memory_path': fixtures_path, 'skip': 'test\w+ner', }) self.collector = MemoryCgroupCollector(config, None) self.collector.collect() should_be_published = { 'lxc.cache': 1, 'lxc.rss': 1, 'lxc.swap': 1, 'system.cache': 1, 'system.rss': 1, 'system.swap': 1, 'lxc.total_cache': 1, 'lxc.total_rss': 1, 'lxc.total_swap': 1, 'system.total_cache': 1, 'system.total_rss': 1, 'system.total_swap': 1, } should_not_be_published = { 'lxc.testcontainer.cache': 1, 'lxc.testcontainer.rss': 1, 'lxc.testcontainer.swap': 1, 'lxc.testcontainer.total_cache': 1, 'lxc.testcontainer.total_rss': 1, 'lxc.testcontainer.total_swap': 1, } [self.assertPublished(publish_mock, k, v) for k, v in should_be_published.iteritems()] [self.assertUnpublished(publish_mock, k, v) for k, v in should_not_be_published.iteritems()]