Ejemplo n.º 1
0
class TestProcessStatCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('ProcessStatCollector', {
            'interval': 1
        })

        self.collector = ProcessStatCollector(config, None)

    def test_import(self):
        self.assertTrue(ProcessStatCollector)

    @patch('__builtin__.open')
    @patch('os.access', Mock(return_value=True))
    @patch.object(Collector, 'publish')
    def test_should_open_proc_stat(self, publish_mock, open_mock):
        open_mock.return_value = StringIO('')
        self.collector.collect()
        open_mock.assert_called_once_with('/proc/stat', 'r')

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        ProcessStatCollector.PROC = self.getFixturePath('proc_stat_1')
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {})

        ProcessStatCollector.PROC = self.getFixturePath('proc_stat_2')
        self.collector.collect()

        metrics = {
            'ctxt': 0,
            'btime': 1319181102,
            'processes': 0,
            'procs_running': 1,
            'procs_blocked': 0,
            'ctxt': 1791,
            'btime': 1319181102,
            'processes': 2,
            'procs_running': 1,
            'procs_blocked': 0,
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)
Ejemplo n.º 2
0
class TestProcessStatCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('ProcessStatCollector', {
            'interval': 1
        })

        self.collector = ProcessStatCollector(config, None)

    def test_import(self):
        self.assertTrue(ProcessStatCollector)

    @patch('__builtin__.open')
    @patch('os.access', Mock(return_value=True))
    @patch.object(Collector, 'publish')
    def test_should_open_proc_stat(self, publish_mock, open_mock):
        open_mock.return_value = StringIO('')
        self.collector.collect()
        open_mock.assert_called_once_with('/proc/stat', 'r')

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        ProcessStatCollector.PROC = self.getFixturePath('proc_stat_1')
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {})

        ProcessStatCollector.PROC = self.getFixturePath('proc_stat_2')
        self.collector.collect()

        metrics = {
            'ctxt': 0,
            'btime': 1319181102,
            'processes': 0,
            'procs_running': 1,
            'procs_blocked': 0,
            'ctxt': 1791,
            'btime': 1319181102,
            'processes': 2,
            'procs_running': 1,
            'procs_blocked': 0,
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)
Ejemplo n.º 3
0
class TestProcessStatCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config("ProcessStatCollector", {"interval": 1})

        self.collector = ProcessStatCollector(config, None)

    @patch("__builtin__.open")
    @patch("os.access", Mock(return_value=True))
    @patch.object(Collector, "publish")
    def test_should_open_proc_stat(self, publish_mock, open_mock):
        open_mock.return_value = StringIO("")
        self.collector.collect()
        open_mock.assert_called_once_with("/proc/stat", "r")

    @patch.object(Collector, "publish")
    def test_should_work_with_real_data(self, publish_mock):
        ProcessStatCollector.PROC = self.getFixturePath("proc_stat_1")
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {})

        ProcessStatCollector.PROC = self.getFixturePath("proc_stat_2")
        self.collector.collect()

        metrics = {
            "ctxt": 0,
            "btime": 1319181102,
            "processes": 0,
            "procs_running": 1,
            "procs_blocked": 0,
            "ctxt": 1791,
            "btime": 1319181102,
            "processes": 2,
            "procs_running": 1,
            "procs_blocked": 0,
        }

        self.setDocExample(
            collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config["path"]
        )
        self.assertPublishedMany(publish_mock, metrics)
Ejemplo n.º 4
0
    def setUp(self):
        config = get_collector_config('ProcessStatCollector', {
            'interval': 1
        })

        self.collector = ProcessStatCollector(config, None)
Ejemplo n.º 5
0
    def setUp(self):
        config = get_collector_config("ProcessStatCollector", {"interval": 1})

        self.collector = ProcessStatCollector(config, None)