HEX
Server: nginx/1.22.0
System: Linux iZuf6jdxbygmf6cco977lcZ 5.10.84-10.4.al8.x86_64 #1 SMP Tue Apr 12 12:31:07 CST 2022 x86_64
User: root (0)
PHP: 7.4.29
Disabled: passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen
Upload Files
File: //usr/local/aegis/PythonLoader/third_party/aegis_checker/offline/check_restart_frequently.py
# -*- coding: utf-8 -*-
import re
import sys

from aegis_checker.common.print_log import *
from aegis_checker.common.aegis_client_log_parser import LogObserver, LOG_INFO


class RestartObserver(LogObserver):
    def __init__(self):
        self.__restart_events = []

    def on_log(self, log_date, log_time, log_type, content, line, line_num, log_file_path):
        """
        2020-04-17 10:05:43 [Info] ====================Start Agent : aegis_10_79,Apr  7 2020 10:14:48====================
        :param line_num:
        :param log_date:
        :param log_time:
        :param log_type: Debug, Info, Warn, Error, Critical
        :param content: log without timestamp and log type : "SendMessage T_MSG_LOGIN"
        :param line: origin log with timestamp and log type
        :return:
        """
        restart_reg = r"====================Start Agent : aegis_(\d{2}_\d{2}),.*===================="
        if log_type == LOG_INFO and re.match(restart_reg, content):
            self.__restart_events.append(self.wrapper_event(log_date, log_time, content))

    def _check_abnormal_restart(self):
        """
        if restart more than 3 time, it may has abnormal restart
        :return:
        """
        restart_times = len(self.__restart_events)
        if restart_times >= 3:
            first_restart_time = self.__restart_events[0]["date"] + self.__restart_events[0]["time"]
            last_restart_time = self.__restart_events[-1]["date"] + self.__restart_events[-1]["time"]
            log_warning("abnormal restart from %s to %s, restart %d times" % (
                first_restart_time, last_restart_time, restart_times))

    def on_end(self, success):
        for restart_events in self.__restart_events:
            log_info("%s %s aegis client restart" % (restart_events["date"], restart_events["time"]))