Exemplo n.º 1
0
    def test_collector_aggregation_when_unknown_values(self):
        collector = WatcherStatsCollector(self._get_streamer(), 'firefox')
        aggregate = {}
        for i in range(0, 10):
            pid = 1000 + i
            aggregate[pid] = {
                'age': 'N/A',
                'children': [],
                'cmdline': 'python',
                'cpu': 'N/A',
                'create_time': 1378663281.96,
                'ctime': '0:00.0',
                'mem': 'N/A',
                'mem_info1': '52K',
                'mem_info2': '39M',
                'nice': 0,
                'pid': pid,
                'username': '******',
                'subtopic': pid,
                'name': 'firefox'
            }

        res = collector._aggregate(aggregate)
        self.assertEqual(res['mem'], 'N/A')
        self.assertEqual(len(res['pid']), 10)
        self.assertEqual(res['cpu'], 'N/A')
Exemplo n.º 2
0
    def test_collector_aggregation_when_unknown_values(self):
        collector = WatcherStatsCollector(self._get_streamer(), 'firefox')
        aggregate = {}
        for i in range(0, 10):
            pid = 1000 + i
            aggregate[pid] = {
                'age': 'N/A', 'children': [], 'cmdline': 'python',
                'cpu': 'N/A', 'create_time': 1378663281.96,
                'ctime': '0:00.0', 'mem': 'N/A', 'mem_info1': '52K',
                'mem_info2': '39M', 'nice': 0, 'pid': pid,
                'username': '******', 'subtopic': pid, 'name': 'firefox'}

        res = collector._aggregate(aggregate)
        self.assertEqual(res['mem'], 'N/A')
        self.assertEqual(len(res['pid']), 10)
        self.assertEqual(res['cpu'], 'N/A')
Exemplo n.º 3
0
    def test_collector_aggregation(self):
        collector = WatcherStatsCollector(self._get_streamer(), 'firefox')
        aggregate = {}
        for i in range(0, 10):
            pid = 1000 + i
            aggregate[pid] = {
                'age': 154058.91111397743, 'children': [],
                'cmdline': 'python', 'cpu': 0.0 + i / 10.,
                'create_time': 1378663281.96,
                'ctime': '0:00.0', 'mem': 0.0 + i / 10,
                'mem_info1': '52K', 'mem_info2': '39M',
                'username': '******', 'subtopic': pid, 'name': 'firefox'}

        res = collector._aggregate(aggregate)
        self.assertEquals(res['mem'], 0)
        self.assertEquals(len(res['pid']), 10)
        self.assertEquals(res['cpu'], 0.45)
Exemplo n.º 4
0
    def test_watcherstats(self):
        calls = defaultdict(int)
        info = []
        for i in range(2):
            info.append({
                'age': 154058.91111397743 + i,
                'children': [],
                'cmdline': 'python',
                'cpu': 0.0 + i / 10.,
                'create_time': 1378663281.96,
                'ctime': '0:00.0',
                'mem': 0.0,
                'mem_info1': '52K',
                'mem_info2': '39M',
                'nice': 0,
                'pid': None,
                'username': '******'
            })

        def _get_info(pid):
            try:
                data = info[calls[pid]].copy()
            except IndexError:
                raise collector_module.util.NoSuchProcess(pid)
            data['pid'] = pid
            calls[pid] += 1
            return data

        old_info = collector_module.util.get_info
        try:
            collector_module.util.get_info = _get_info

            self.pids['firefox'] = [2353, 2354]
            collector = WatcherStatsCollector(self._get_streamer(), 'firefox')

            stats = list(collector.collect_stats())
            self.assertEqual(len(stats), 3)

            stats = list(collector.collect_stats())
            self.assertEqual(len(stats), 3)

            stats = list(collector.collect_stats())
            self.assertEqual(len(stats), 1)

            self.circus_pids = {1234: 'ohyeah'}
            self.pids['circus'] = [1234]
            collector = WatcherStatsCollector(self._get_streamer(), 'circus')
            stats = list(collector.collect_stats())
            self.assertEqual(stats[0]['name'], 'ohyeah')

        finally:
            collector_module.util.get_info = old_info
Exemplo n.º 5
0
    def test_collector_aggregation(self):
        collector = WatcherStatsCollector(self._get_streamer(), 'firefox')
        aggregate = {}
        for i in range(0, 10):
            pid = 1000 + i
            aggregate[pid] = {
                'age': 154058.91111397743,
                'children': [],
                'cmdline': 'python',
                'cpu': 0.0 + i / 10.,
                'create_time': 1378663281.96,
                'ctime': '0:00.0',
                'mem': 0.0 + i / 10,
                'mem_info1': '52K',
                'mem_info2': '39M',
                'username': '******',
                'subtopic': pid,
                'name': 'firefox'
            }

        res = collector._aggregate(aggregate)
        self.assertEquals(res['mem'], 0)
        self.assertEquals(len(res['pid']), 10)
        self.assertEquals(res['cpu'], 0.45)
Exemplo n.º 6
0
    def test_watcherstats(self):
        calls = defaultdict(int)
        info = []
        for i in range(2):
            info.append({
                'age': 154058.91111397743 + i,
                'children': [],
                'cmdline': 'python',
                'cpu': 0.0 + i/10.,
                'create_time': 1378663281.96,
                'ctime': '0:00.0',
                'mem': 0.0,
                'mem_info1': '52K',
                'mem_info2': '39M',
                'nice': 0,
                'pid': None,
                'username': '******'})

        def _get_info(pid):
            try:
                data = info[calls[pid]].copy()
            except IndexError:
                raise collector_module.util.NoSuchProcess(pid)
            data['pid'] = pid
            calls[pid] += 1
            return data

        try:
            old_info = collector_module.util.get_info
            collector_module.util.get_info = _get_info

            self.pids['firefox'] = [2353, 2354]
            collector = WatcherStatsCollector(self._get_streamer(), 'firefox')

            stats = list(collector.collect_stats())
            self.assertEquals(len(stats), 3)

            stats = list(collector.collect_stats())
            self.assertEquals(len(stats), 3)

            stats = list(collector.collect_stats())
            self.assertEquals(len(stats), 1)

            self.circus_pids = {1234: 'ohyeah'}
            self.pids['circus'] = [1234]
            collector = WatcherStatsCollector(self._get_streamer(), 'circus')
            stats = list(collector.collect_stats())
            self.assertEquals(stats[0]['name'], 'ohyeah')

        finally:
            collector_module.util.get_info = old_info