• Shell测试性能相关脚本


      利用传递参数的形式对当前的内容进行测试

    #!/bin/sh
    Interval=5
    A=1000
    Free=`cat /proc/meminfo|grep "MemFree" | awk '{print $2}'`
    if [ ! -f "pidconf" ]       
    then
        echo "FILE pidconf NOT FOUND!"
        exit
    fi
    if [ ! -f "result" ]     #不存在result这个file就touch一个
    then
        touch result
    fi
    if [ ! -d "pidbak" ]     #如果不存在pidbak这个目录directory就创建pidbak这个目录
    then
       mkdir pidbak
    fi
    mv pidfile/* pidbak       
    while [ 1 ]
    do
    echo "`date`" >> result
    while read line
    do 
    if [ ! -f "pidfile/$line" ]
    then
    touch pidfile/$line 
    old=`pgrep $line`
    new=$old
    echo "$old" > pidfile/$line
    else
    old=`cat pidfile/$line`
    new=`pgrep $line`
    if [ $? != 0 ]
    then
    new="NULL"
    fi
    fi
    if [ ${old} != ${new} ]
    then
    echo "===ERROR===[$line] pid change, [$old=>$new]" >> result
    echo "$new" > pidfile/$line
    else
    echo "==SUCCESS==[$line=$new]" >> result
    fi
    done < pidconf
    
    
    sleep 10
    Free1=`cat /proc/meminfo|grep "MemFree" | awk '{print $2}'`
    T=`expr $Free - $Free1`
    if [ $T -le $A ]
    then
    echo "========memory normal======" >> result
    else
    echo "========memory leak========" >> result
    fi
    if [ $# != 1 ];then
        echo "wrong parameter!"
        exit 1
    fi
    checktime=$1
    check=1
    allcpu=0
    maxcpu=0
    mincpu=100
    while [ $check -le $checktime ]
    do
        docpu=`cpu -c 1`
        cucpu=`echo $docpu | cut -b 11-14 | cut -d \% -f 1`
        if [ $cucpu -gt $maxcpu ];then
            maxcpu=$cucpu
        fi
        if [ $cucpu -lt $mincpu ];then
            mincpu=$cucpu
        fi
        allcpu=`expr $allcpu + $cucpu`
        avcpu=`expr $allcpu / $check`
        echo "Average:$avcpu%  Now:$docpu"
        check=`expr $check + 1`
    done
    echo "MAX CPU: $maxcpu%  MIN CPU: $mincpu%" >> result
    echo "" >> result
    sleep $Interval
    done
    

      

    #!/bin/sh
    echo "Read Config..."
    while read line;
    do
        eval "$line"
    done < perfConf
    cat perfConf
    echo "Read Config Successfully!"
    echo "Ip Test..."
    if [ $Protocol == "UDP" ]
    then
        iperf -c $Ip -u -t 1 > connectData 2>&1
    else
        iperf -c $Ip -t 1 > connectData 2>&1
    fi
    if [[ `grep -c "failed" connectData` -eq "1" ]]
    then
        echo "ERROR:iperf server can not connect"
        exit 0
    	fi
    	echo "Ip Test Successfully!"
    	function rand()
    {
        min=$1
        max=$(($2-$min+1))
       #num=$(tr -cd 1-9 < /dev/urandom 1 | head -c 10)
        num=$(tr -cd 1-9 < /proc/sys/kernel/random/uuid 1 | head -c 10)
        echo $(($num%$max+$min))
    }
    
    if [[ $Mode == "Auto" ]]
    then
        myloop=1
        echo "Begin to Auto Test..."
        echo ""
        while [ $myloop -le $Loop ]
        do
    	echo "==="`date`"==="
            echo "===NO."$myloop" Loop==="
            if [[ $Protocol == "UDP" ]]
            then
                len=$(rand $Start_Len $End_Len)
                bd=$(rand $Start_Bandwidth $End_Bandwidth)"K"
                echo "iperf -c "$Ip" -t "$CircleTime" -u -b "$bd" -l "$len" -p "$Port" -i "$Interval
                    iperf -c $Ip -t $CircleTime -u -b $bd -l $len -p $Port -i $Interval
            else
                echo "iperf -c "$Ip" -t "$CircleTime" -i "$Interval" -p "$Port
                iperf -c $Ip -t $CircleTime -i $Interval -p $Port
            fi
            let myloop=myloop+1
            echo "=============================="
            echo ""
            sleep $SleepTime
        done
    	else
        echo "Begin to Passive Test..."
        if [[ $Protocol == "UDP" ]]
        then
            iperf -c $Ip -t $Time -u -b $Bandwidth -i $Interval
        else
    	iperf -c $Ip -t $Time  -i $Interval
        fi
    fi
    

      

  • 相关阅读:
    Vue父子组件传值之——访问根组件$root、$parent、$children和$refs
    js判断是否为ie浏览器,精确显示各个ie版本
    在JS/jQuery中,怎么触发input的keypress/keydown/keyup事件?
    HTML中a标签自动识别电话、邮箱
    如何彻底删除Mac磁盘中的文件
    使用Understand for Mac编写您的第一个API脚本
    如何将MacOS Catalina降级为Mojave
    macOS Catalina 10.15.1 发布 全新 Emoji、支持 AirPods Pro
    WingIDE Pro 7如何新建项目
    忘记MacBook密码的解决技巧!
  • 原文地址:https://www.cnblogs.com/chenxiaomeng/p/13265919.html
Copyright © 2020-2023  润新知