class TestLoadAverageCollector(CollectorTestCase): def setUp(self): config = get_collector_config('LoadAverageCollector', { 'interval': 10 }) self.collector = LoadAverageCollector(config, None) @patch('__builtin__.open') @patch('os.access', Mock(return_value=True)) @patch.object(Collector, 'publish') def test_should_open_proc_loadavg(self, publish_mock, open_mock): open_mock.return_value = StringIO('') self.collector.collect() open_mock.assert_called_once_with('/proc/loadavg') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): LoadAverageCollector.PROC = self.getFixturePath('proc_loadavg') self.collector.collect() metrics = { '01': (0.00, 2), '05': (0.32, 2), '15': (0.56, 2), 'processes_running': 1, 'processes_total': 235 } self.setDocExample(self.collector.__class__.__name__, metrics) self.assertPublishedMany(publish_mock, metrics)
class TestLoadAverageCollector(CollectorTestCase): def setUp(self): config = get_collector_config('LoadAverageCollector', {'interval': 10}) self.collector = LoadAverageCollector(config, None) @patch('__builtin__.open') @patch('os.access', Mock(return_value=True)) @patch.object(Collector, 'publish') def test_should_open_proc_loadavg(self, publish_mock, open_mock): open_mock.return_value = StringIO('') self.collector.collect() open_mock.assert_called_once_with('/proc/loadavg') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): LoadAverageCollector.PROC = self.getFixturePath('proc_loadavg') self.collector.collect() metrics = { '01': (0.00, 2), '05': (0.32, 2), '15': (0.56, 2), 'processes_running': 1, 'processes_total': 235 } self.setDocExample(self.collector.__class__.__name__, metrics) self.assertPublishedMany(publish_mock, metrics)
class BaseCollector(diamond.collector.Collector): def __init__(self, config=None, handlers=[], name=None, configfile=None): super(BaseCollector, self).__init__(config, handlers, name, configfile) self.cpu_collector = CPUCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.memory_collector = MemoryCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.loadavg_collector = LoadAverageCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.network_collector = NetworkCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.diskusage_collector = DiskUsageCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.diskspace_collector = DiskSpaceCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.vmstat_collector = VMStatCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) def get_default_config_help(self): config_help = super(BaseCollector, self).get_default_config_help() config_help.update({ 'simple': 'run simple mode on of its sub collectors', }) return config_help def get_default_config(self): config = super(BaseCollector, self).get_default_config() return config def collect(self): self.cpu_collector.collect() self.memory_collector.collect() self.loadavg_collector.collect() self.network_collector.collect() self.diskusage_collector.collect() self.diskspace_collector.collect() self.vmstat_collector.collect() return True
class TestLoadAverageCollector(CollectorTestCase): def setUp(self): config = get_collector_config("LoadAverageCollector", {"interval": 10}) self.collector = LoadAverageCollector(config, None) @patch("__builtin__.open") @patch("os.access", Mock(return_value=True)) @patch.object(Collector, "publish") def test_should_open_proc_loadavg(self, publish_mock, open_mock): open_mock.return_value = StringIO("") self.collector.collect() open_mock.assert_called_once_with("/proc/loadavg") @patch.object(Collector, "publish") def test_should_work_with_real_data(self, publish_mock): LoadAverageCollector.PROC = self.getFixturePath("proc_loadavg") self.collector.collect() metrics = {"01": (0.00, 2), "05": (0.32, 2), "15": (0.56, 2), "processes_running": 1, "processes_total": 235} self.setDocExample( collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config["path"] ) self.assertPublishedMany(publish_mock, metrics)
class TestLoadAverageCollector(CollectorTestCase): def setUp(self): config = get_collector_config('LoadAverageCollector', { 'interval': 10 }) self.collector = LoadAverageCollector(config, None) def test_import(self): self.assertTrue(LoadAverageCollector) @patch('__builtin__.open') @patch('os.access', Mock(return_value=True)) @patch.object(Collector, 'publish') def test_should_open_proc_loadavg(self, publish_mock, open_mock): if not os.path.exists('/proc/loadavg'): # on platforms that don't provide /proc/loadavg: don't bother # testing this. return open_mock.return_value = StringIO('') self.collector.collect() open_mock.assert_called_once_with('/proc/loadavg') @patch('multiprocessing.cpu_count') @patch('os.getloadavg') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock, getloadavg_mock, cpu_count_mock): LoadAverageCollector.PROC_LOADAVG = self.getFixturePath('proc_loadavg') getloadavg_mock.return_value = (0.12, 0.23, 0.34) cpu_count_mock.return_value = 2 self.collector.collect() metrics = { '01': (0.12, 2), '05': (0.23, 2), '15': (0.34, 2), '01_normalized': (0.06, 2), '05_normalized': (0.115, 2), '15_normalized': (0.17, 2), 'processes_running': 1, 'processes_total': 235 } self.setDocExample(collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config['path']) self.assertPublishedMany(publish_mock, metrics)
class BaseCollector(diamond.collector.Collector): def __init__(self, config=None, handlers=[], name=None, configfile=None): super(BaseCollector, self).__init__(config, handlers, name, configfile) self.cpu_collector = CPUCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.memory_collector = MemoryCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.loadavg_collector = LoadAverageCollector( config=self.config, configfile=self.configfile, handlers=self.handlers) self.network_collector = NetworkCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) self.diskusage_collector = DiskUsageCollector( config=self.config, configfile=self.configfile, handlers=self.handlers) self.diskspace_collector = DiskSpaceCollector( config=self.config, configfile=self.configfile, handlers=self.handlers) self.vmstat_collector = VMStatCollector(config=self.config, configfile=self.configfile, handlers=self.handlers) def get_default_config_help(self): config_help = super(BaseCollector, self).get_default_config_help() config_help.update({ 'simple': 'run simple mode on of its sub collectors', }) return config_help def get_default_config(self): config = super(BaseCollector, self).get_default_config() return config def collect(self): self.cpu_collector.collect() self.memory_collector.collect() self.loadavg_collector.collect() self.network_collector.collect() self.diskusage_collector.collect() self.diskspace_collector.collect() self.vmstat_collector.collect() return True
class TestLoadAverageCollector(CollectorTestCase): def setUp(self): config = get_collector_config('LoadAverageCollector', {'interval': 10}) self.collector = LoadAverageCollector(config, None) def test_import(self): self.assertTrue(LoadAverageCollector) @patch('__builtin__.open') @patch('os.access', Mock(return_value=True)) @patch.object(Collector, 'publish') def test_should_open_proc_loadavg(self, publish_mock, open_mock): if not os.path.exists('/proc/loadavg'): # on platforms that don't provide /proc/loadavg: don't bother # testing this. return open_mock.return_value = StringIO('') self.collector.collect() open_mock.assert_called_once_with('/proc/loadavg') @patch('multiprocessing.cpu_count') @patch('os.getloadavg') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock, getloadavg_mock, cpu_count_mock): LoadAverageCollector.PROC_LOADAVG = self.getFixturePath('proc_loadavg') getloadavg_mock.return_value = (0.12, 0.23, 0.34) cpu_count_mock.return_value = 2 self.collector.collect() metrics = { '01': (0.12, 2), '05': (0.23, 2), '15': (0.34, 2), '01_normalized': (0.06, 2), '05_normalized': (0.115, 2), '15_normalized': (0.17, 2), 'processes_running': 1, 'processes_total': 235 } self.setDocExample(collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config['path']) self.assertPublishedMany(publish_mock, metrics)