Browse Source

add drop_cache

master
lework 4 years ago
parent
commit
755d245dda
  1. 22
      python/supervisor_healthCheck.py

22
python/supervisor_healthCheck.py

@ -4,7 +4,7 @@
# @Time : 2020-06-05 # @Time : 2020-06-05
# @Author : lework # @Author : lework
# @Desc : 针对supervisor的应用进行健康检查 # @Desc : 针对supervisor的应用进行健康检查
# @Version : 1.6 # @Version : 1.7
import os import os
@ -69,6 +69,14 @@ def shell(cmd):
proc.wait() proc.wait()
return (proc.returncode,) + proc.communicate() return (proc.returncode,) + proc.communicate()
def drop_cache():
"""
清除缓存, 1: pagecache, 2: dentries and inodes, 3: 1+2
"""
cmd = "sync && echo 1 > /proc/sys/vm/drop_caches"
exitcode, _, _ = shell(cmd)
return exitcode
def get_proc_cpu(pid): def get_proc_cpu(pid):
""" """
@ -554,6 +562,12 @@ class HealthCheck(object):
time.sleep(1) time.sleep(1)
info = s.supervisor.getProcessInfo(program) info = s.supervisor.getProcessInfo(program)
drop_cache_state = drop_cache()
if drop_cache_state == 0:
self.log(program, '[Action: restart] drop pagecache success.')
else:
self.log(program, '[Action: restart] drop pagecache error.')
if info['state'] != 20: if info['state'] != 20:
try: try:
start_result = s.supervisor.startProcess(program) start_result = s.supervisor.startProcess(program)
@ -605,6 +619,12 @@ class HealthCheck(object):
result = 'Failed to kill %s, pid: %s exiting: %s' % (program, pid, exitcode) result = 'Failed to kill %s, pid: %s exiting: %s' % (program, pid, exitcode)
self.log(program, "[Action: kill] result %s", result) self.log(program, "[Action: kill] result %s", result)
drop_cache_state = drop_cache()
if drop_cache_state == 0:
self.log(program, '[Action: kill] drop pagecache success.')
else:
self.log(program, '[Action: kill] drop pagecache error.')
return result return result
def action_email(self, program, action_type, msg, check_status): def action_email(self, program, action_type, msg, check_status):

Loading…
Cancel
Save