frp占用CPU过高自动结束进程脚本

frp占用CPU过高自动结束进程脚本

新建一个脚本killfrpc.sh将下面的代码复制进去

#!/bin/sh
# monitor frpc used CPU
record=0
while true;
do
cpu=$(top -b -n1 | grep "frpc" | head -1 | awk '{print $9}')
pid=$(top -b -n1 | grep "frpc" | head -1 | awk '{print $1}')
#cpu check
result=${cpu/.*}
if [[ $record == $pid ]];then kill -9 $pid;echo "$pid was killed";fi
if [[ $result > 95 || $result == 100 ]];then let record=${pid};else let record=0;fi
#echo
echo `date +%F" "%H:%M:%S`+" cpu:$result% record pid:$record pid:$pid"
sleep 60
done

使用方法

screen -S kill
sh ./killfrpc.sh

配合frp进程守护脚本实现frp自动重启