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"]))