查看syslog-ng内存,兼容容器情况

    syslog_pid=`ps -ef|grep syslog-ng|grep -v grep |awk '{print $2}'`
    pid_count=`ps -ef|grep syslog-ng|grep -v grep |awk '{print $2}'| wc -l`
    cpu_count=`cat /proc/cpuinfo | grep "core id" | wc -l`
    SYSLOG_CPU_MAX=0
    if [[ $syslog_pid"X" == "X" ]];then
        return
    fi
    for i in `seq 1 $pid_count`;do
        SYSLOG_PID=$(echo $syslog_pid |cut -d " " -f$i)
        cpu_total_slice_1=`cat /proc/stat|grep "cpu "|awk '{for(i=2;i<=NF;i++)j+=$i;print j;}'`
        cpu_process_total_slice_1=`cat /proc/$SYSLOG_PID/stat|awk '{print  $14+$15+$16+$17}'`
        sleep 1
        cpu_total_slice_2=`cat /proc/stat|grep "cpu "|awk '{for(i=2;i<=NF;i++)j+=$i;print j;}'`
        cpu_process_total_slice_2=`cat /proc/$SYSLOG_PID/stat|awk '{print  $14+$15+$16+$17}'`

        cpu_n_a=`echo "scale=2;($cpu_process_total_slice_2-$cpu_process_total_slice_1) / ($cpu_total_slice_2-$cpu_total_slice_1) * $cpu_count " | bc -l`
        cpu_n=`echo $cpu_n_a |tr -d "."`
        if [[ $SYSLOG_CPU_MAX < $cpu_n ]];then
            SYSLOG_CPU_MAX=$cpu_n
        fi
    done
    if [[ $SYSLOG_CPU_MAX -lt 5 ]];then
        echo "syslog_ng_cpu=0-5"
    elif [[ $SYSLOG_CPU_MAX -lt 20 ]];then
        echo "syslog_ng_cpu=5-20"
    elif [[ $SYSLOG_CPU_MAX -lt 50 ]];then
        echo "syslog_ng_cpu=20-50"
    elif [[ $SYSLOG_CPU_MAX -lt 80 ]];then
        echo "syslog_ng_cpu=50-80"
    elif [[ $SYSLOG_CPU_MAX -ge 80 ]];then
        echo "syslog_ng_cpu>80"
    fi
上一篇:gulp使用1-入门指南


下一篇:CYUSB3014固件部分低版本工程在Eclipse中编译得到img文件时无效的解决方案