Beispiel #1
0
class SystemAggregator(object):
    def __init__(self):
        self._cpu_collector = CpuCollector()
        self._disk_collector = DiskCollector()
        self._memory_collector = MemoryCollector()
        self._network_collector = NetworkCollector()

    def get_usage(self):
        return {
            "CPU": self._cpu_collector.get_usage(),
            "Disk": self._disk_collector.get_usage(),
            "Memory": self._memory_collector.get_usage(),
            "Network": self._network_collector.get_usage()
        }

    def get_cpu_usage(self):
        return self._cpu_collector.get_usage()

    def get_disk_usage(self):
        return self._disk_collector.get_usage()

    def get_memory_usage(self):
        return self._memory_collector.get_usage()

    def get_network_usage(self):
        return self._network_collector.get_usage()

    def __str__(self):
        return json.dumps(self.get_usage(), indent=4, sort_keys=True)
    def setUp(self):
        config = get_collector_config('NetworkCollector', {
            'interval': 10,
            'interfaces' : [ 'lo', 'eth0' ]
        })

        self.collector = NetworkCollector(config, None)
class TestNetworkCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('NetworkCollector', {
            'interval': 10,
            'interfaces' : [ 'lo', 'eth0' ]
        })

        self.collector = NetworkCollector(config, None)
    
    @patch('__builtin__.open')
    @patch.object(Collector, 'publish')
    def test_should_open_proc_net_dev(self, publish_mock, open_mock):
        open_mock.return_value = StringIO('')
        self.collector.collect()
        open_mock.assert_called_once_with('/proc/net/dev')

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        NetworkCollector.PROC = get_fixture_path('proc_net_dev_1')
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {})

        NetworkCollector.PROC = get_fixture_path('proc_net_dev_2')
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'lo.rx_mbytes'   : (0.0, 2),
            'lo.tx_mbytes'   : (0.0, 2),
            'eth0.rx_mbytes' : (2.504, 2),
            'eth0.tx_mbytes' : (4.707, 2)
        })
Beispiel #4
0
 def __init__(self):
     self._cpu_collector = CpuCollector()
     self._disk_collector = DiskCollector()
     self._memory_collector = MemoryCollector()
     self._network_collector = NetworkCollector()