Ejemplo n.º 1
0
    def server_down(h: History) -> float:
        try:
            load_log = h.get_range(position=1, time_range='1m', null_value=0)
            high_load = max(load_log) > 90 if len(load_log) != 0 else None

            error_log = h.get_range(position=2, time_range='2m')
            critical = any(error_log == 'critical')
            warning = any(error_log == 'warning')

            return 'server down' if critical or (warning
                                                 and high_load) else None
        except Exception as err:
            print('error:', err)
Ejemplo n.º 2
0
    def test_simple_time_range(self):
        events = [
            Time('2020-02-10', step='5m'),
            Linear(start=0, step=1),
            Linear(start=0, step=-1),
        ]
        history = History()
        history.start(events_count=len(events))
        for _ in range(10):
            for position, event in enumerate(events):
                event.position = position
                history.set_event(event, event.generate())

        self.assertEqual([10, 9, 8], list(history.get_range(1, '15m')))
        self.assertEqual([-10, -9, -8], list(history.get_range(2, '15m')))
        self.assertEqual([10, 9, 8], list(history.get_range(1, '720s')))