Linux监控

#!/bin/bash
mem_total=`free | awk 'NR==2{print $2}'`
mem_use=`free | awk 'NR==2{print $3}'`
mem_use_rate=`awk 'BEGIN{print('$mem_use'/'$mem_total')*100}'`
current_time=$(date "+%Y-%m-%d %H:%M:%S")
echo $current_time
pid=$(ps | grep "linksdwan" |grep "usr"|awk '{print $1}')
log=/root/$current_time.txt
link_mem=$(cat /proc/$pid/status | grep 'VmSize')
echo $mem_use_rate
process=$$
echo $process

while :;
do
    echo '***'
    if [ $mem_use_rate > 90 ]; then
        kill -9 $process
    fi
    sleep 60
    echo $current_time"-----Mem_use_rate"$mem_use_rate"---"$link_mem >> $log
done

你可能感兴趣的:(Linux监控)