Go检测内存泄漏定时重启
作者:
珍惜Any | 来源:发表于
2020-11-12 11:26 被阅读0次#!/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
本文标题:Go检测内存泄漏定时重启
本文链接:https://www.haomeiwen.com/subject/nhoubktx.html
网友评论