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
def setUp(self): config = get_collector_config('MemoryCollector', { 'interval': 10, 'byte_unit': 'kilobyte' }) self.collector = MemoryCollector(config, None)
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)
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 TestMemoryCollector(CollectorTestCase): def setUp(self): config = get_collector_config('MemoryCollector', { 'interval': 10, 'byte_unit': 'kilobyte' }) self.collector = MemoryCollector(config, None) def test_import(self): self.assertTrue(MemoryCollector) @patch('__builtin__.open') @patch('os.access', Mock(return_value=True)) @patch.object(Collector, 'publish') def test_should_open_proc_meminfo(self, publish_mock, open_mock): open_mock.return_value = StringIO('') self.collector.collect() open_mock.assert_called_once_with('/proc/meminfo') @patch.object(Collector, 'publish') def test_should_work_with_real_data(self, publish_mock): MemoryCollector.PROC = self.getFixturePath('proc_meminfo') self.collector.collect() metrics = { 'MemTotal': 49554212, 'MemFree': 35194496, 'MemAvailable': 35194496, 'MemUsedPercentage': 28.98, 'Buffers': 1526304, 'Cached': 10726736, 'Active': 10022168, 'Dirty': 24748, 'Inactive': 2524928, 'Shmem': 276, 'SwapTotal': 262143996, 'SwapFree': 262143996, 'SwapCached': 0, 'VmallocTotal': 34359738367, 'VmallocUsed': 445452, 'VmallocChunk': 34311049240 } self.setDocExample(collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config['path']) self.assertPublishedMany(publish_mock, metrics)
def setUp(self): config = get_collector_config('MemoryCollector', { 'interval' : 10, 'byte_unit' : 'kilobyte' }) self.collector = MemoryCollector(config, None)
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)
class TestMemoryCollector(CollectorTestCase): def setUp(self): config = get_collector_config("MemoryCollector", {"interval": 10, "byte_unit": "kilobyte"}) self.collector = MemoryCollector(config, None) def test_import(self): self.assertTrue(MemoryCollector) @patch("__builtin__.open") @patch("os.access", Mock(return_value=True)) @patch.object(Collector, "publish") def test_should_open_proc_meminfo(self, publish_mock, open_mock): open_mock.return_value = StringIO("") self.collector.collect() open_mock.assert_called_once_with("/proc/meminfo") @patch.object(Collector, "publish") def test_should_work_with_real_data(self, publish_mock): MemoryCollector.PROC = self.getFixturePath("proc_meminfo") self.collector.collect() metrics = { "MemTotal": 49554212, "MemFree": 35194496, "Buffers": 1526304, "Cached": 10726736, "Active": 10022168, "Dirty": 24748, "Inactive": 2524928, "Shmem": 276, "SwapTotal": 262143996, "SwapFree": 262143996, "SwapCached": 0, "VmallocTotal": 34359738367, "VmallocUsed": 445452, "VmallocChunk": 34311049240, } self.setDocExample( collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config["path"] ) self.assertPublishedMany(publish_mock, metrics)
def setUp(self): config = get_collector_config("MemoryCollector", {"interval": 10, "byte_unit": "kilobyte"}) self.collector = MemoryCollector(config, None)