Skip to content

Commit 755d245

Browse files
committed
add drop_cache
1 parent 61400a4 commit 755d245

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

python/supervisor_healthCheck.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# @Time : 2020-06-05
55
# @Author : lework
66
# @Desc : 针对supervisor的应用进行健康检查
7-
# @Version : 1.6
7+
# @Version : 1.7
88

99

1010
import os
@@ -69,6 +69,14 @@ def shell(cmd):
6969
proc.wait()
7070
return (proc.returncode,) + proc.communicate()
7171

72+
def drop_cache():
73+
"""
74+
清除缓存, 1: pagecache, 2: dentries and inodes, 3: 1+2
75+
"""
76+
cmd = "sync && echo 1 > /proc/sys/vm/drop_caches"
77+
exitcode, _, _ = shell(cmd)
78+
79+
return exitcode
7280

7381
def get_proc_cpu(pid):
7482
"""
@@ -554,6 +562,12 @@ def action_supervisor_restart(self, program):
554562
time.sleep(1)
555563
info = s.supervisor.getProcessInfo(program)
556564

565+
drop_cache_state = drop_cache()
566+
if drop_cache_state == 0:
567+
self.log(program, '[Action: restart] drop pagecache success.')
568+
else:
569+
self.log(program, '[Action: restart] drop pagecache error.')
570+
557571
if info['state'] != 20:
558572
try:
559573
start_result = s.supervisor.startProcess(program)
@@ -605,6 +619,12 @@ def action_kill(self, program, pid):
605619
result = 'Failed to kill %s, pid: %s exiting: %s' % (program, pid, exitcode)
606620
self.log(program, "[Action: kill] result %s", result)
607621

622+
drop_cache_state = drop_cache()
623+
if drop_cache_state == 0:
624+
self.log(program, '[Action: kill] drop pagecache success.')
625+
else:
626+
self.log(program, '[Action: kill] drop pagecache error.')
627+
608628
return result
609629

610630
def action_email(self, program, action_type, msg, check_status):

0 commit comments

Comments
 (0)