Go检测内存泄漏定时重启

2020-11-12  本文已影响0人  珍惜Any
#!/usr/bin/zsh
mem=$(free | grep "Mem:" |awk '{print ($2-$7)/$2}')
targetmem=0.22
echo $mem
if [ $(expr $mem \> $targetmem) -eq 1  ]; then
echo $mem
echo $(ps -ef | grep -E 'rpc_server_go' | grep -v 'grep' | awk '{print $2}')
kill -9 $(ps -ef | grep -E 'rpc_server_go' | grep -v 'grep' | awk '{print $2}')
kill_result=$?
d="`date +%Y-%m-%d,%H:%m:%s`"
echo '内存大于阈值, 开始关闭go服务, 当前时间: '$d ' 执行结果: ' $kill_result
source /etc/profile
nohup /q/rpc_server_go/rpc_server_go  > /q/rpc_server_go/log.$d  &
start_result=$?
$d="`date +%Y-%m-%d,%H:%m:%s`"
echo 'go服务开始启动, 当前时间: ' $d '执行结果: ' $start_result
echo $(ps -ef | grep -E 'rpc_server_go' | grep -v 'grep' | awk '{print $2}')
fi
上一篇 下一篇

猜你喜欢

热点阅读