|
4 | 4 | # @Time : 2020-06-05
|
5 | 5 | # @Author : lework
|
6 | 6 | # @Desc : 针对supervisor的应用进行健康检查
|
7 |
| -# @Version : 1.6 |
| 7 | +# @Version : 1.7 |
8 | 8 |
|
9 | 9 |
|
10 | 10 | import os
|
@@ -69,6 +69,14 @@ def shell(cmd):
|
69 | 69 | proc.wait()
|
70 | 70 | return (proc.returncode,) + proc.communicate()
|
71 | 71 |
|
| 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 |
72 | 80 |
|
73 | 81 | def get_proc_cpu(pid):
|
74 | 82 | """
|
@@ -554,6 +562,12 @@ def action_supervisor_restart(self, program):
|
554 | 562 | time.sleep(1)
|
555 | 563 | info = s.supervisor.getProcessInfo(program)
|
556 | 564 |
|
| 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 | + |
557 | 571 | if info['state'] != 20:
|
558 | 572 | try:
|
559 | 573 | start_result = s.supervisor.startProcess(program)
|
@@ -605,6 +619,12 @@ def action_kill(self, program, pid):
|
605 | 619 | result = 'Failed to kill %s, pid: %s exiting: %s' % (program, pid, exitcode)
|
606 | 620 | self.log(program, "[Action: kill] result %s", result)
|
607 | 621 |
|
| 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 | + |
608 | 628 | return result
|
609 | 629 |
|
610 | 630 | def action_email(self, program, action_type, msg, check_status):
|
|
0 commit comments