Write Process Monitor with Python

xiaoxiao2021-03-06  89

There is an application is not very stable, and it is temporarily found. If you only know that the log file will be reflected. The application timing update the log directory, there are two log files: fromclient.log record reception request, fromserver.log record reception The server returns. When there is a problem, it is generally the version of the future in the update, but fromServer.log stops. Ling machine moves, why not write a monitor log program, find the program is automatically restarted, so that the customer is seriously affected by customers Use it. For more time to completely solve the problem. So the following code: #! / Bin / env python # - * - CODING: CP936 - * - Import Glob, OS, Time, Stat, SYS

DEADFLAG = 60 # Judging the number of seconds that the process is dead

Def getFileTime (filename): return os.stat (filename) [stat.st_ctime]

Def main ():

Path = Glob.glob ("../ log / proxy *") [- 1]

CLIFILE = PATH "/" "mt.log" SVRFILE = PATH "/" "fromserver.log"

Clitime = getFileTime (clifile) svrtime = getFileTime (svrfile)

Print Clifile, Time.localtime (CLITIME) Print Svrfile, Time.localtime (Svrtime) IF ABS (SVRTIME-CLITIME)> DeadFlag: Print "Time is over! Will Restart!" os.system ("sh / home / esm / bin /RESTART_TCPPROXY.SH ") Return

IF __NAME__ == "__main__": main ()

转载请注明原文地址:https://www.9cbs.com/read-95599.html

New Post(0)