Exemplo n.º 1
0
    def test_munin_output(self):

        cfg = self.make_basic_cfg()

        plugin = self.create_plugin(cfg)

        jsfr = JSONFileReporter(output_file=self.filename)
        register_reporter(jsfr)
        test1 = EventCounter("test1")
        register_counter(test1)

        try:
            test1.report_event("test1", "value", 2)

            output_report()

            plugin.output_data(cfg)
            self.assertEqual(self.get_last_plugin_output(), ["multigraph test", "test1.value 2"])

            plugin.max_file_age_in_seconds = 0.00001
            self.clear_last_plugin_output()
            plugin.output_data(cfg)
            self.assertEqual(self.get_last_plugin_output(), [])

            plugin.max_file_age_in_seconds = None
            plugin.output_data(cfg)
            self.assertEqual(self.get_last_plugin_output(), ["multigraph test", "test1.value 2"])

            os.unlink(self.filename)
        finally:
            unregister_counter(counter=test1)
            unregister_reporter(jsfr)
Exemplo n.º 2
0
    def test_registry_get_values(self):
        reg = CounterRegistry(EventDispatcher())
        test1 = EventCounter("test1")
        reg.add_counter(test1)
        test2 = EventCounter("test2")
        reg.add_counter(test2)

        test1.report_event("test1", "value", 2)

        test2.report_event("test1", "value", 3)

        self.assertEquals(reg.get_values().values, {"test1": 2, "test2": 3})
Exemplo n.º 3
0
    def test_json_output(self):
        filename = "/tmp/json_test.txt"
        jsfr = JSONFileReporter(output_file=filename)
        test1 = EventCounter("test1")
        register_counter(test1)
        register_reporter(jsfr)

        try:
            test1.report_event("test1", "value", 2)

            output_report()
            report = JSONFileReporter.safe_read(filename)
            report = dict([(k, v) for k, v in report.iteritems() if not k.startswith("__")])
            self.assertEqual(report, {"test1": 2})

            os.unlink(filename)
        finally:
            unregister_counter(counter=test1)
            unregister_reporter(jsfr)
Exemplo n.º 4
0
    def test_basic_reporter(self):

        test1 = EventCounter("test1", events=["test_event"])
        register_counter(test1)

        v = SimpleValueReporter()
        register_reporter(v)
        start_auto_reporting(0.01)

        try:
            test1.report_event("test_event", "value", 2)

            sleep(0.1)
            self.assertEqual(v.values_wo_metadata, {"test1": 2})

            test1.report_event("test_event", "value", 1)
            sleep(0.05)
            self.assertEqual(v.values_wo_metadata, {"test1": 3})

            stop_auto_reporting()
            test1.report_event("test_event", "value", 1)
            sleep(0.05)
            self.assertEqual(v.values_wo_metadata, {"test1": 3})
        finally:
            unregister_counter(counter=test1)
            unregister_reporter(v)