使用步骤:
1.设置一个定时任何 执行getperf.sh,采集性能数据
2.将采集到性能数据文件,如:192.168.1.1.tar.gz 解压
3.将性能分析的脚步performance_analyse.sh 放到解压后的目录中
4.安装gnuplot程序
5.将字体文件夹,拷贝到/usr/share/fonts/目录
6.直接运行 bash performance_analyse.sh

本文提到的脚本和字体文件可以在下载中心下载,链接如下:

http://down.51cto.com/data/2053872

getperf.sh脚本内容如下:

#################################################
#说明:
# 定义时间TIMES参数,表示采集的次数,
# 采集时间 = TIMES * INTERVAL
#eg:
# TIMES=180 , INTERVAL=10  采集时间就是半小时
#
#################################################
#!/bin/bash
TIMES=3600
INTERVAL=2
PWD=`pwd`
TIME=`date "+%F %H:%M:%S"`
TAR=`whereis tar|awk -F ":" '{print $2}'|awk '{print $1}'`
SAR=`whereis sar|awk -F ":" '{print $2}'|awk '{print $1}'`
IOSTAT=`whereis iostat|awk -F ":" '{print $2}'|awk '{print $1}'`
# Check Moniter Tool
SysInfo(){echo "sysip : $SYSIP"|tee $PWD/$SYSIP/sysinfoecho "starttime : $TIME" |tee -a $PWD/$SYSIP/sysinfo/sbin/ifconfig >>$PWD/$SYSIP/sysinfoecho "===================================" >>$PWD/$SYSIP/sysinfo/usr/sbin/dmidecode >>$PWD/$SYSIP/sysinfoecho "===================================" >>$PWD/$SYSIP/sysinfo/bin/cat /proc/cpuinfo >> $PWD/$SYSIP/sysinfoecho "===================================" >>$PWD/$SYSIP/sysinfo/sbin/fdisk -l >> $PWD/$SYSIP/sysinfoecho "===================================" >>$PWD/$SYSIP/sysinfo/bin/df -Th >>$PWD/$SYSIP/sysinfoecho "===================================" >>$PWD/$SYSIP/sysinfo/usr/bin/free -m >> $PWD/$SYSIP/sysinfoecho "===================================" >>$PWD/$SYSIP/sysinfo    echo ""
}
CheckEnv(){PUB_IP=`/sbin/ifconfig |grep "inet addr" | awk -F: '{print $2}'| awk '{print $1}'|grep -v "172\.\|10\.\|127\.\|192\."|sed -n 1p`PRI_IP=`/sbin/ifconfig |grep "inet addr" | awk -F: '{print $2}'| awk '{print $1}'|grep "10\.\|127\.\|192\."|sed -n 1p`if [ "snda$PUB_IP" == "snda" ];thenSYSIP=$PRI_IPelseSYSIP=$PUB_IPfiif [ -d $PWD/$SYSIP ];thenrm -rf $PWD/$SYSIPfimkdir -p $PWD/$SYSIPif ! grep iostat /usr/bin/iostat ;thenyum -y install sysstatfi
}
GetPerf(){CPUUSAGE="$PWD/$SYSIP/cpuusage.log"MEMUSAGE="$PWD/$SYSIP/memusage.log"DISKUSAGE="$PWD/$SYSIP/diskusage.log"NETWORK="$PWD/$SYSIP/network.log"$SAR -P ALL $INTERVAL $TIMES>> $CPUUSAGE &$IOSTAT -dkx $INTERVAL $TIMES>> $DISKUSAGE &$SAR -n DEV $INTERVAL $TIMES>> $NETWORK &$SAR -r $INTERVAL $TIMES>> $MEMUSAGE &for ((i=0;i<$TIMES;i++))dosleep $INTERVALdone
}
CheckEnv
SysInfo
GetPerf
#在同一台机器上第二次采集数据时,会删除之前采集的数据,重新采集
#采集完成之后,会生产一个以 IP.tar.gz的压缩包。将这个压缩包,放到
#分析脚本performance_analyse.sh 的同级目录。
if [ -d $PWD/$SYSIP ];thencd $PWDrm -f $SYSIP.tar.gztar zcvf $SYSIP.tar.gz $SYSIP
fi

performance_analyse.sh脚本内容如下:

#################################################
#
#    这个脚本的作用是处理由性能采集脚本收集到的性能数据
#然后使用gunplot生产直观的性能图。
#
#################################################
#!/bin/bash
SysInfo(){local file=$1local productname="unknow"local cpumodel="unknow"local cpucore="unknow"local cpumhz="unknow"local physical="unknow"local realcpucore="unknow"local diskpart="unknow"local memory="unknow"ipaddr=`cat $file |grep -i "net addr"|grep -v "127"`    productname=`cat $file |grep -i "product name"`cpumodel=`cat $file |grep -i "model name"|uniq -d`cpucore=`cat $file |grep  "processor"|wc -l`cpumhz=`cat $file |grep -i "cpu MHz"|uniq -d`physical=`cat $file |grep -i "physical id"|sort -n|uniq -d|wc -l`realcpucore=`cat $file |grep -i "cpu cores"|uniq -d|awk -F ":" '{print $2}'`memory=` cat $file |grep -i -EB1 "mem:"`diskpart=`cat $file |grep -i "disk"|grep -E "[shv][d][a-z]"`echo "System Information:"|tee -a $REPORTFILEecho "IP address:"|tee -a $REPORTFILEecho -e "$ipaddr"|tee -a $REPORTFILEecho "$productname" |tee -a $REPORTFILEecho -e "\t$cpumodel" |tee -a $REPORTFILEecho -e "\tCPU cores\t:$cpucore"|tee -a $REPORTFILEecho -e "\t$cpumhz"|tee -a $REPORTFILEecho -e "\tPhysical cpu number:$physical"|tee -a $REPORTFILEecho -e "\tEach CPU real core:$realcpucore"|tee -a $REPORTFILEecho "$diskpart"|tee -a $REPORTFILEecho -e "Memory(MB):\n$memory"|tee -a $REPORTFILE
}
CpuAllUsage(){local file=$1cat $file|grep -i "all"|grep -v -i -E "average|linux|system" >$GNUPLOTFOLDER/sar_cpu.$$TITLE=`cat $file |sed "/^$/d"|grep -v -i "average|linux"|sed 1d|sed -n 1p`local SOURCE_SAR_CPU="$GNUPLOTFOLDER/sar_cpu.$$"local USER_UASGE=`echo $TITLE |awk '{print $3}'`local NICE_UASGE=`echo $TITLE |awk '{print $4}'`local SYSTEM_UASGE=`echo $TITLE |awk '{print $5}'`local IOWAIT_UASGE=`echo $TITLE |awk '{print $6}'`local STEAL_UASGE=`echo $TITLE |awk '{print $7}'`local IDLE_UASGE=`echo $TITLE |awk '{print $8}'`local cpuusagemax=`cat $SOURCE_SAR_CPU|awk '{print $3+$4+$5+$6+$7}'|sort -r|sed -n 1p`local Tmp_ylable=`echo $cpuusagemax|awk -F "." '{print $1}'`local ylable=`echo $Tmp_ylable+5|bc`local cpuusagemin=`cat $SOURCE_SAR_CPU|awk '{print $3+$4+$5+$6+$7}'|sort|sed -n 1p`local cpuusageavg=`awk 'BEGIN{total=0}{total+=$8}END{print 100-total/NR}' $SOURCE_SAR_CPU`echo "`date '+%F %H:%M:%S'`: CPU Performance analysis" |tee -a $REPORTFILEecho -e "\t1.System Cpu load(%) \tmax=$cpuusagemax,average=$cpuusageavg,mim=$cpuusagemin" |tee -a $REPORTFILE
/usr/local/bin/gnuplot --persist <<EOF
set term png size 800,600
#================= Cpu usage area pic ===========
set output "TotalCpuUsage.png"
set key title "Total CPU usage(%)"
set key box 3
set key below
set xlabel "times"
set ylabel "TOTAL CPU USAGE(%)"
set style fill solid 1
set style histogram rowstacked
plot [1:][0:$ylable] '$SOURCE_SAR_CPU' using 3 with histogram lt rgb "#FFB3B3" title "$USER_UASGE",\
'' using 4 with histogram title "$NICE_UASGE",\
'' using 5 with histogram lt rgb "#B3CA7E" title "$SYSTEM_UASGE",\
'' using 6 with histogram lt rgb "#A464BF" title "$IOWAIT_UASGE",\
'' using 7 with histogram title "$STEAL_UASGE",\
'' using 8 with histogram lt rgb "#212121" title "$IDLE_UASGE",\
$cpuusagemax lt 4 lw 2 title "Max Usage ($cpuusagemax%)"
EOF
}
CpuEachCoreUsage(){local file=$1sed -i 's/PM//g' $filelocal corenu=`cat $file|grep -v -i -E "average|system|all|linux"|sed "/^$/d"|awk '{print $2}'|sort -n -r|uniq -d|sed -n 1p`
#    echo $corenuPLOT=""echo "">$GNUPLOTFOLDER/idle_sum.$$for (( i=0;i<=$corenu;i++ ))docat $file |grep -v -i -E "average|system|all|linux"|sed "/^$/d"|awk "(\$2==$i){print}"|awk '{print $1 ," ",100-$8}'>$GNUPLOTFOLDER/$i.txtlocal idlesum=`awk 'BEGIN{total=0}{total+=$2}END{print total}' $GNUPLOTFOLDER/$i.txt`echo $i $idlesum >>$GNUPLOTFOLDER/idle_sum.$$donefirst_load=`cat $GNUPLOTFOLDER/idle_sum.$$|sort -n -k 2 -r|sed -n 1p|awk '{print $1}'`second_load=`cat $GNUPLOTFOLDER/idle_sum.$$|sort -n -k 2 -r|sed -n 2p|awk '{print $1}'`third_load=`cat $GNUPLOTFOLDER/idle_sum.$$|sort -n -k 2 -r|sed -n 3p|awk '{print $1}'`load=($first_load $second_load $third_load)echo -e "\t2.Each core load:"local cpuload=("First" "Second" "Third")local nu=0for i in  ${load[@]}    dolocal coreloadmax=`cat $GNUPLOTFOLDER/$i.txt|sort -n -k 2 -r|sed -n 1p|awk '{print $2}'`local coreloadavg=`awk 'BEGIN{total=0}{total+=$2}END{print total/NR}' $GNUPLOTFOLDER/$i.txt`local coreloadmin=`cat $GNUPLOTFOLDER/$i.txt|sort -n -k 2|sed -n 1p|awk '{print $2}'`echo -e "\t\t\t Load ${cpuload[$nu]} core $i : max=$coreloadmax , avg=$coreloadavg , min=$coreloadmin"|tee -a $REPORTFILEnu=`echo $nu+1|bc`done    for ((i=0;i<=corenu;i++))doif [ $i -eq $first_load ];thenLW=4elif [ $i -eq $second_load ];thenLW=3elif [ $i -eq $third_load ];thenLW=2elseLW=1fiTMP1="$GNUPLOTFOLDER/$i.txt" TMP2="using 1:2 with l lw $LW"TMP3="core $i "PLOT="$PLOT \"$TMP1\" $TMP2 title  \"$TMP3\","donelocal tmp_ylabel_range=`cat $file|grep -v -i -E "average|system|all|linux"|sed "/^$/d"|awk '{print 100-$8}'|sort -n -r|sed -n 1p|awk -F "." '{print $1}'|sed -n 1p`local ylabel_range=`echo $tmp_ylabel_range+5|bc`
/usr/local/bin/gnuplot --persist <<EOF
#=============== Each core usage =====================
set term png size 800,600
set output "CpuCoreIdle.png"
set key title "Each Core Usage(%)"
set key box 3
set key below
set ylabel "CPU Core Usage(%)"
set xdata time
set timefmt "%H:%M:%S"
plot [:][0:$ylabel_range] $PLOT
EOF
}
MemoryUsage(){local file=$1local title=`cat $file |sed '/^$/d'|grep -i -E -v "average|linux"|grep -i mem`sed -i 's/PM//g' $filelocal kbmemused=`echo $title|awk '{print $3}'` local memused=`echo $title|awk '{print $4}'` local kbbuffers=`echo $title|awk '{print $5}'` local kbcached=`echo $title|awk '{print $6}'` local kbcommit=`echo $title|awk '{print $7}'` cat $file |sed '/^$/d'|grep -i -E -v "average|linux"|grep -i -v mem|awk '{print $1,$2/1024,($2+$3)/1024,$3/1024,$4,$5/1024,$6/1024}'>$GNUPLOTFOLDER/memory.$$SOURCE_FILE=$GNUPLOTFOLDER/memory.$$local memtotal=`awk 'BEGIN{total=0}{total+=$3}END{print total/NR}' $SOURCE_FILE`local memusedmax=`awk '{print $4}' $SOURCE_FILE|sort -n -r|sed -n 1p`local memusedavg=`awk 'BEGIN{total=0}{total+=$4}END{print total/NR}' $SOURCE_FILE`local memusedmin=`awk '{print $4}' $SOURCE_FILE|sort -n|sed -n 1p`local memfreemax=`awk '{print $2}' $SOURCE_FILE|sort -n -r|sed -n 1p`local memfreeavg=`awk 'BEGIN{total=0}{total+=$2}END{print total/NR}' $SOURCE_FILE`local memfreemin=`awk '{print $2}' $SOURCE_FILE|sort -n|sed -n 1p`local memcachemax=`awk '{print $7}' $SOURCE_FILE|sort -n -r|sed -n 1p`local memcacheavg=`awk 'BEGIN{total=0}{total+=$7}END{print total/NR}' $SOURCE_FILE`local memcachemin=`awk '{print $7}' $SOURCE_FILE|sort -n|sed -n 1p`local memused_cachemax=`awk '{print $4-$7}' $SOURCE_FILE|sort -n -r|sed -n 1p`local memused_cacheavg=`awk 'BEGIN{total=0}{total+=($4-$7)}END{print total/NR}' $SOURCE_FILE`local memused_cachemin=`awk '{print $4-$7}' $SOURCE_FILE|sort -n|sed -n 1p`local used_percent=`awk 'BEGIN{total=0}{total+=$5}END{print total/NR}' $SOURCE_FILE`echo "`date '+%F %H:%M:%S'`: Memory usage analysis" |tee -a $REPORTFILEecho -e "\t\t1.total memory: $memtotal MB"|tee -a $REPORTFILEecho -e "\t\t2.memory used: max=$memusedmax MB ,avg=$memusedavg MB ,min=$memusedmin MB"|tee -a $REPORTFILEecho -e "\t\t3.memory free: max=$memfreemax MB ,avg=$memfreeavg MB ,min=$memfreemin MB"|tee -a $REPORTFILEecho -e "\t\t4.memory cache: max=$memcachemax MB ,avg=$memcacheavg MB ,min=$memcachemin MB"|tee -a $REPORTFILEecho -e "\t\t4.memory used-cache: max=$memused_cachemax MB ,avg=$memused_cacheavg MB ,min=$memused_cachemin MB"|tee -a $REPORTFILE
/usr/local/bin/gnuplot --persist <<EOF
set term png size 800,600
set output "MemoryUsage.png"
set key title "Memory Use state"
set key box 3
set key below
set ylabel "MB"
set y2label "(%)"
set x2range [0:]
set y2range [0:100]
set xdata time
set timefmt "%H:%M:%S"
set xtics;set x2tics;set ytics ;set y2tics;
plot '$SOURCE_FILE' using 1:3 w p title "Total Memory",'' using 1:4 w p title "Used",'' using 1:7 w p title "Cached"  ,\
'' using 5 with l lt rgb "red" title "memused($used_percent%)" axis x2y2
EOF
}
DiskUsage(){local file=$1cat $file |sed "/^$/d"|grep -v -i -E "device|linux"|sed 1d >$GNUPLOTFOLDER/disk.$$local SOURCE_FILE=$GNUPLOTFOLDER/disk.$$plot_readiops=""plot_writeiops=""local nu=1echo "`date '+%F %H:%M:%S'`: Disk Performance analysis" |tee -a $REPORTFILEfor diskpart in `cat $file |sed '1,2d'|grep -v -i "device"|awk -F " " '{print $1}'|sort|uniq -d|sed '/^$/d'|grep -E "^[a-z][a-z][a-z]$"`doawk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE >$GNUPLOTFOLDER/gnu_tmpfile.$diskpartplot_readiops="$plot_readiops \"$GNUPLOTFOLDER/gnu_tmpfile.$diskpart\" using  4 w l title \"$diskpart read IOPS\","awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk 'BEGIN{total=0}{total+=$4}END{print total/NR}'>$GNUPLOTFOLDER/t.$$local read_avg_iops=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $4}'|sort -n|sed -n 1p>$GNUPLOTFOLDER/t.$$local read_min_iops=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $4}'|sort -n -r |sed -n 1p>$GNUPLOTFOLDER/t.$$local read_max_iops=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$plot_writeiops="$plot_writeiops \"$GNUPLOTFOLDER/gnu_tmpfile.$diskpart\" using  5 w l title \"$diskpart write IOPS\","awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk 'BEGIN{total=0}{total+=$5}END{print total/NR}'>$GNUPLOTFOLDER/t.$$local write_avg_iops=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $5}'|sort -n|sed -n 1p>$GNUPLOTFOLDER/t.$$local write_min_iops=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $5}'|sort -n -r |sed -n 1p>$GNUPLOTFOLDER/t.$$local write_max_iops=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk 'BEGIN{total=0}{total+=$6}END{print total/NR}'>$GNUPLOTFOLDER/t.$$local avg_read_throughput=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $6}'|sort -n|sed -n 1p>$GNUPLOTFOLDER/t.$$local min_read_throughput=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $6}'|sort -n -r |sed -n 1p>$GNUPLOTFOLDER/t.$$local max_read_throughput=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk 'BEGIN{total=0}{total+=$7}END{print total/NR}'>$GNUPLOTFOLDER/t.$$local avg_write_throughput=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $7}'|sort -n|sed -n 1p>$GNUPLOTFOLDER/t.$$local min_write_throughput=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $7}'|sort -n -r |sed -n 1p>$GNUPLOTFOLDER/t.$$local max_write_throughput=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk 'BEGIN{total=0}{total+=$10}END{print total/NR}'>$GNUPLOTFOLDER/t.$$local avg_await=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $10}'|sort -n|sed -n 1p>$GNUPLOTFOLDER/t.$$local min_await=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$awk "(\$1==\"$diskpart\"){print}" $SOURCE_FILE|awk '{print $10}'|sort -n -r |sed -n 1p>$GNUPLOTFOLDER/t.$$local max_await=`cat $GNUPLOTFOLDER/t.$$`rm -f $GNUPLOTFOLDER/t.$$echo -e "\t\t$nu.$diskpart performance:"|tee -a $REPORTFILEecho -e "\t\t\t read iops:\t\t max=$read_max_iops ,\t avg=$read_avg_iops ,\t min=$read_min_iops"|tee -a $REPORTFILEecho -e "\t\t\t write iops:\t\t max=$write_max_iops ,\t avg=$write_avg_iops ,\t min=$write_min_iops"|tee -a $REPORTFILEecho -e "\t\t\t read data per second:\t max=$max_read_throughput KB,\t avg=$avg_read_throughput KB,\t min=$min_read_throughput KB"|tee -a $REPORTFILEecho -e "\t\t\t write data per second:\t max=$max_write_throughput KB,\t avg=$avg_write_throughput KB,\t min=$min_write_throughput KB"|tee -a $REPORTFILEecho -e "\t\t\t each io wait time:\t max=$max_await ms ,\t avg=$avg_await ms ,\t min=$min_await ms"|tee -a $REPORTFILEdone/usr/local/bin/gnuplot --persist <<EOF
set term png size 800,600
set output "DiskIOPSPerformance.png"
set key title "Disk IOPS"
set key box 3
set key below
set ylabel "IOPS"
plot $plot_readiops $plot_writeiops
EOF
}
NetworkPerformance(){local file=$1sed -i 's/PM//g' $filecat $file |grep -E "eth|em"|grep -v -i "average">$GNUPLOTFOLDER/network_sourcefile.txtlocal sourcefile=$GNUPLOTFOLDER/network_sourcefile.txtlocal titlerxpackage=`cat $file |grep -i "IFACE"|awk '{print $3}'|uniq -d`local titletxpackage=`cat $file |grep -i "IFACE"|awk '{print $4}'|uniq -d`local titlerxbyte=`cat $file |grep -i "IFACE"|awk '{print $5}'|uniq -d`local titletxbyte=`cat $file |grep -i "IFACE"|awk '{print $6}'|uniq -d`if [ $titlerxbyte == 'rxkB/s' ];thenunit="KB"elif [ $titlerxbyte == 'rxbyt/s' ];thenunit="byte"filocal rxpackage=''local txpackage=''local rxbyte=''local txbyte=''local nu=1echo "`date '+%F %H:%M:%S'`: Network Performance analysis" |tee -a $REPORTFILEfor netcard in `cat $file |grep -E "eth|em"|grep -v -i "average"|awk '{print $2}'|sort|uniq -d`docat $sourcefile|grep $netcard>$GNUPLOTFOLDER/gnu_network.$netcardrxpackage="$rxpackage \"$GNUPLOTFOLDER/gnu_network.$netcard\" using 1:3 w l title \"$netcard $titlerxpackage\","txpackage="$txpackage \"$GNUPLOTFOLDER/gnu_network.$netcard\" using 1:4 w l title \"$netcard $titletxpackage\","rxbyte="$rxbyte  \"$GNUPLOTFOLDER/gnu_network.$netcard\" using 1:5 w l title \"$netcard $titlerxbyte\","txbyte="$txbyte  \"$GNUPLOTFOLDER/gnu_network.$netcard\" using 1:6 w l title \"$netcard $titletxbyte\","max_rxpck=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -r -k 3|sed -n 1p|awk '{print $4}'`      avg_rxpck=`awk 'BEGIN{total=0}{total+=$3}END{print total/NR}' $GNUPLOTFOLDER/gnu_network.$netcard`min_rxpck=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -k 3|sed -n 1p|awk '{print $4}'`      max_txpck=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -r -k 4|sed -n 1p|awk '{print $5}'`      avg_txpck=`awk 'BEGIN{total=0}{total+=$4}END{print total/NR}' $GNUPLOTFOLDER/gnu_network.$netcard`min_txpck=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -k 4|sed -n 1p|awk '{print $5}'`      max_rxbyt=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -r -k 5|sed -n 1p|awk '{print $6}'`      avg_rxbyt=`awk 'BEGIN{total=0}{total+=$5}END{print total/NR}' $GNUPLOTFOLDER/gnu_network.$netcard`min_rxbyt=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -k 5|sed -n 1p|awk '{print $6}'`      max_txbyt=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -r -k 6|sed -n 1p|awk '{print $7}'`      avg_txbyt=`awk 'BEGIN{total=0}{total+=$6}END{print total/NR}' $GNUPLOTFOLDER/gnu_network.$netcard`min_txbyt=` cat $GNUPLOTFOLDER/gnu_network.$netcard|sort -n -k 6|sed -n 1p|awk '{print $7}'`      echo -e "\t\t$nu.$netcard load:"|tee -a $REPORTFILEecho -e "\t\t\t rxpck/s:\t\t max=$max_rxpck ,\t avg=$avg_rxpck ,\t min=$min_rxpck"|tee -a $REPORTFILEecho -e "\t\t\t txpck/s:\t\t max=$max_txpck ,\t avg=$avg_txpck ,\t min=$min_txpck"|tee -a $REPORTFILEecho -e "\t\t\t rxbyt/s:\t max=$max_rxbyt $unit,\t avg=$avg_rxbyt $unit,\t min=$min_rxbyt $unit"|tee -a $REPORTFILEecho -e "\t\t\t txbyt/s:\t max=$max_txbyt $unit,\t avg=$avg_txbyt $unit,\t min=$min_txbyt $unit"|tee -a $REPORTFILEnu=`echo $nu+1|bc`done
/usr/local/bin/gnuplot --persist <<EOF
set term png size 800,600
set output "NetworkPackagePerformance.png"
set key title "network performance"
set key box 3
set key below
set ylabel "Package/s"
set xdata time
set timefmt "%H:%M:%S"
plot $rxpackage $txpackage
EOF
/usr/local/bin/gnuplot --persist <<EOF
set term png size 800,600
set output "NetworkThougtputPerformance.png"
set key title "Throughput performance"
set key box 3
set key below
set ylabel "$unit"
set xdata time
set timefmt "%H:%M:%S"
plot $rxbyte $txbyte
EOF
}
#定义gnuplot的字体msttcore目录及字体,这个在压缩包里有,放到指定目录即可。
export GDFONTPATH="/usr/share/fonts/msttcore"
export GNUPLOT_DEFAULT_GDFONT="arial"
SYSINFO_FILE=sysinfo
CPU_USAGE_FILE=cpuusage.log
MEMORY_USAGE_FILE=memusage.log
DISK_USAGE_FILE=diskusage.log
NETWORK_USAGE_FILE=network.log
PWD=`pwd`
REPORTFILE=report.txt
GNUPLOTFOLDER="/tmp/gnuplotlinux"
mkdir -p $GNUPLOTFOLDER
#Time=`date '+%F %H:%M:%S'`
echo -e "\t\t\t\t\t\tSDG Aystem Analysis Report" > $REPORTFILE
SysInfo $SYSINFO_FILE
echo "" >> $REPORTFILE
CpuAllUsage $CPU_USAGE_FILE
CpuEachCoreUsage $CPU_USAGE_FILE
echo "" >> $REPORTFILE
MemoryUsage $MEMORY_USAGE_FILE
echo "" >> $REPORTFILE
DiskUsage $DISK_USAGE_FILE
echo "" >> $REPORTFILE
NetworkPerformance $NETWORK_USAGE_FILE
echo "" >> $REPORTFILE
#脚本执行完成之后,会在性能数据所在的目录中生成
#report.txt     性能报告文本
#TotalCpuUsage.png   CPU利用率图表
#CpuCoreIdle.png     每个CPU核心的Idle
#MemoryUsage.png     内存使用率
#DiskIOPSPerformance.png   磁盘IOPS性能
#NetworkPackagePerformance.png    网卡发包率性能
#NetworkThougtputPerformance.png  网卡吞吐性能
#################################################

收集系统性能数据并通过gnuplot绘图相关推荐

  1. Node_exporter+Prometheus+Grafana 快速实现Linux系统性能数据提取、存储和可视化展示

    Node_exporter+Prometheus+Grafana 快速实现Linux系统性能数据提取.存储和可视化展示 1. 前言 2. Node_exporter 2.1 安装 node_expor ...

  2. gnuplot绘图学习

    Gnuplot 是一种免费分发的绘图工具,可以移植到各种主流平台,也可以使用编程语言产生的数据进行绘图 1.配置gnuplot 为了能在命令窗口运行gnuplot,需要将gnuplot.exe路径添加 ...

  3. gnuplot绘图程序中对线型(linetype)、点型(pointtype)、线条宽度(linewidth)、点大小(pointsize)、图样

    作者:magj77 原作网址:http://blog.sina.com.cn/s/blog_6a5f098201013tvb.html 在NS2的gnuplot绘图程序中对线型(linetype).点 ...

  4. 《C》C语言编程实现任意阶数的“m序列”并通过gnuplot绘图——在知道本原多项式的前提下

    关于m序列的构建方法 在我之前的博客中已详细介绍,请点击→\rightarrow→C语言编程实现指定阶"m序列"并通过gnuplot绘图 一.C语言编程实现任意阶m序列 1. 任意 ...

  5. 《C》C语言编程实现任意阶数的“Gold序列”并通过gnuplot绘图——在知道本原多项式的前提下

    关于Gold序列的构建方法 在我之前的博客中已详细介绍,请点击→\rightarrow→C语言编程实现指定阶"Gold序列"并通过gnuplot绘图 一.C语言编程实现任意阶Gol ...

  6. gnuplot绘图技巧

    Gnuplot 是一种免费分发的绘图工具,可以移植到各种主流平台.它可以下列两种模式之一进行操作:当需要调整和修饰图表使其正常显示时,通过在 gnuplot 提示符中发出命令,可以在交互模式下操作该工 ...

  7. 使用 SNMP 读取和收集性能数据

    大多数连接到网络的设备使用 SNMP(简单网络管理协议)报告其状态.该协议主要用于管理和监控网络连接的硬件设备,但一些应用程序也使用该协议公开其统计数据.在本章中,我们将了解如何从 Python 应用 ...

  8. Gnuplot绘图入门1——sin(x)绘制与美化

    Gnuplot绘图入门1--sin(x)绘制与美化 gnuplot是一个跨平台且免费的交互式绘图软件,可以根据我们提供的函数或数据绘制二维/三维图形,还能生成GIF动画. 在linux命令行或wind ...

  9. Facebook 被指收集用户数据:通过照片和文本

    北京时间5月25日消息,在加利福尼亚州进行的对Facebook泄露用户信息一案中,法院对Facebook提起一项新的诉讼,指控该公司通过App收集了用户及他们朋友的信息. 上周向加利福尼亚州圣马特奥市 ...

最新文章

  1. 数据库表初始化,删除所有数据后主键ID从1开始
  2. Work measurement II
  3. 机器学习入门---------numpy
  4. (C++版)链表(二)——实现单项循环链表创建、插入、删除等操作
  5. DTS开发记录(5)-- 挑战增量导出
  6. CentOS下yum操作gnome和kde桌面
  7. CCF201809-2 买菜
  8. 内向的人能做管理吗?
  9. Machine Learning In Action 第二章学习笔记: kNN算法
  10. python urllib下载文件怎么停止_python下载文件的三种方法
  11. python: Requests库的一些高级特性
  12. 微信公众平台开发(五) 天气预报功能开发
  13. 常见的html内lian联元素,CSS基础:块元素、内联元素、内联块元素
  14. ios vue 添加本地音乐_苹果手机vue怎么添加自己的音乐
  15. 阿里云OSS对象存储基础入门
  16. One Drive 回收站文件太多时无法清空回收站解决办法
  17. 天津工业大学c语言题库,天津工业大学计算机专业C语言经典笔记
  18. AlexeyAB中训练命令行中 -map 以及 -dont_show
  19. weblogic unable to get file lock问题解决方案
  20. 在HTML中插入SVG的几种方式

热门文章

  1. python3 判断文件是否存在_Python判断文件是否存在的三种方法
  2. uniapp小程序的getsysteminfo_Typecho小程序:Pisces-Mini-Program
  3. sql server datetime取年月_快速定位数据库性能问题,RDS推出慢SQL统计分析
  4. 计算机应用类专业综合知识模拟试题,2015年湖南省对口升学计算机应用类专业综合知识试题(真题)...
  5. 学生信息管理系统c语言课设,学生信息管理系统C语言课设.doc
  6. 新华三社招流程_【面试经验|校招】新华三/产品经理
  7. mysql创建表失败
  8. idea新建web工程
  9. Django讲课笔记01:Django简介
  10. Java案例:Java版生命游戏