编写Bash Shell通过gnuplot绘制系统性能数据图的方法
使用步骤:
1.设置一个定时任何执行getperf.sh,采集性能数据
2.将采集到性能数据文件,如:192.168.1.1.tar.gz解压
3.将性能分析的脚步performance_analyse.sh放到解压后的目录中
4.安装gnuplot程序(这里下载)
5.将字体文件夹,拷贝到/usr/share/fonts/目录
6.直接运行bashperformance_analyse.sh
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=`whereistar|awk-F":"'{print$2}'|awk'{print$1}'` SAR=`whereissar|awk-F":"'{print$2}'|awk'{print$1}'` IOSTAT=`whereisiostat|awk-F":"'{print$2}'|awk'{print$1}'` #CheckMoniterTool SysInfo(){ echo"sysip:$SYSIP"|tee$PWD/$SYSIP/sysinfo echo"starttime:$TIME"|tee-a$PWD/$SYSIP/sysinfo /sbin/ifconfig>>$PWD/$SYSIP/sysinfo echo"===================================">>$PWD/$SYSIP/sysinfo /usr/sbin/dmidecode>>$PWD/$SYSIP/sysinfo echo"===================================">>$PWD/$SYSIP/sysinfo /bin/cat/proc/cpuinfo>>$PWD/$SYSIP/sysinfo echo"===================================">>$PWD/$SYSIP/sysinfo /sbin/fdisk-l>>$PWD/$SYSIP/sysinfo echo"===================================">>$PWD/$SYSIP/sysinfo /bin/df-Th>>$PWD/$SYSIP/sysinfo echo"===================================">>$PWD/$SYSIP/sysinfo /usr/bin/free-m>>$PWD/$SYSIP/sysinfo echo"===================================">>$PWD/$SYSIP/sysinfo echo"" } CheckEnv(){ PUB_IP=`/sbin/ifconfig|grep"inetaddr"|awk-F:'{print$2}'|awk'{print$1}'|grep-v"172\.\|10\.\|127\.\|192\."|sed-n1p` PRI_IP=`/sbin/ifconfig|grep"inetaddr"|awk-F:'{print$2}'|awk'{print$1}'|grep"10\.\|127\.\|192\."|sed-n1p` if["snda$PUB_IP"=="snda"];then SYSIP=$PRI_IP else SYSIP=$PUB_IP fi if[-d$PWD/$SYSIP];then rm-rf$PWD/$SYSIP fi mkdir-p$PWD/$SYSIP if!grepiostat/usr/bin/iostat;then yum-yinstallsysstat fi } GetPerf(){ CPUUSAGE="$PWD/$SYSIP/cpuusage.log" MEMUSAGE="$PWD/$SYSIP/memusage.log" DISKUSAGE="$PWD/$SYSIP/diskusage.log" NETWORK="$PWD/$SYSIP/network.log" $SAR-PALL$INTERVAL$TIMES>>$CPUUSAGE& $IOSTAT-dkx$INTERVAL$TIMES>>$DISKUSAGE& $SAR-nDEV$INTERVAL$TIMES>>$NETWORK& $SAR-r$INTERVAL$TIMES>>$MEMUSAGE& for((i=0;i<$TIMES;i++)) do sleep$INTERVAL done } CheckEnv SysInfo GetPerf #在同一台机器上第二次采集数据时,会删除之前采集的数据,重新采集 #采集完成之后,会生产一个以IP.tar.gz的压缩包。将这个压缩包,放到 #分析脚本performance_analyse.sh的同级目录。 if[-d$PWD/$SYSIP];then cd$PWD rm-f$SYSIP.tar.gz tarzcvf$SYSIP.tar.gz$SYSIP fi
performance_analyse.sh脚本内容如下:
################################################# # #这个脚本的作用是处理由性能采集脚本收集到的性能数据 #然后使用gunplot生产直观的性能图。 # ################################################# #!/bin/bash SysInfo(){ localfile=$1 localproductname="unknow" localcpumodel="unknow" localcpucore="unknow" localcpumhz="unknow" localphysical="unknow" localrealcpucore="unknow" localdiskpart="unknow" localmemory="unknow" ipaddr=`cat$file|grep-i"netaddr"|grep-v"127"` productname=`cat$file|grep-i"productname"` cpumodel=`cat$file|grep-i"modelname"|uniq-d` cpucore=`cat$file|grep"processor"|wc-l` cpumhz=`cat$file|grep-i"cpuMHz"|uniq-d` physical=`cat$file|grep-i"physicalid"|sort-n|uniq-d|wc-l` realcpucore=`cat$file|grep-i"cpucores"|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"SystemInformation:"|tee-a$REPORTFILE echo"IPaddress:"|tee-a$REPORTFILE echo-e"$ipaddr"|tee-a$REPORTFILE echo"$productname"|tee-a$REPORTFILE echo-e"\t$cpumodel"|tee-a$REPORTFILE echo-e"\tCPUcores\t:$cpucore"|tee-a$REPORTFILE echo-e"\t$cpumhz"|tee-a$REPORTFILE echo-e"\tPhysicalcpunumber:$physical"|tee-a$REPORTFILE echo-e"\tEachCPUrealcore:$realcpucore"|tee-a$REPORTFILE echo"$diskpart"|tee-a$REPORTFILE echo-e"Memory(MB):\n$memory"|tee-a$REPORTFILE } CpuAllUsage(){ localfile=$1 cat$file|grep-i"all"|grep-v-i-E"average|linux|system">$GNUPLOTFOLDER/sar_cpu.$$ TITLE=`cat$file|sed"/^$/d"|grep-v-i"average|linux"|sed1d|sed-n1p` localSOURCE_SAR_CPU="$GNUPLOTFOLDER/sar_cpu.$$" localUSER_UASGE=`echo$TITLE|awk'{print$3}'` localNICE_UASGE=`echo$TITLE|awk'{print$4}'` localSYSTEM_UASGE=`echo$TITLE|awk'{print$5}'` localIOWAIT_UASGE=`echo$TITLE|awk'{print$6}'` localSTEAL_UASGE=`echo$TITLE|awk'{print$7}'` localIDLE_UASGE=`echo$TITLE|awk'{print$8}'` localcpuusagemax=`cat$SOURCE_SAR_CPU|awk'{print$3+$4+$5+$6+$7}'|sort-r|sed-n1p` localTmp_ylable=`echo$cpuusagemax|awk-F"."'{print$1}'` localylable=`echo$Tmp_ylable+5|bc` localcpuusagemin=`cat$SOURCE_SAR_CPU|awk'{print$3+$4+$5+$6+$7}'|sort|sed-n1p` localcpuusageavg=`awk'BEGIN{total=0}{total+=$8}END{print100-total/NR}'$SOURCE_SAR_CPU` echo"`date'+%F%H:%M:%S'`:CPUPerformanceanalysis"|tee-a$REPORTFILE echo-e"\t1.SystemCpuload(%)\tmax=$cpuusagemax,average=$cpuusageavg,mim=$cpuusagemin"|tee-a$REPORTFILE /usr/local/bin/gnuplot--persist<<EOF settermpngsize800,600 #=================Cpuusageareapic=========== setoutput"TotalCpuUsage.png" setkeytitle"TotalCPUusage(%)" setkeybox3 setkeybelow setxlabel"times" setylabel"TOTALCPUUSAGE(%)" setstylefillsolid1 setstylehistogramrowstacked plot[1:][0:$ylable]'$SOURCE_SAR_CPU'using3withhistogramltrgb"#FFB3B3"title"$USER_UASGE",\ ''using4withhistogramtitle"$NICE_UASGE",\ ''using5withhistogramltrgb"#B3CA7E"title"$SYSTEM_UASGE",\ ''using6withhistogramltrgb"#A464BF"title"$IOWAIT_UASGE",\ ''using7withhistogramtitle"$STEAL_UASGE",\ ''using8withhistogramltrgb"#212121"title"$IDLE_UASGE",\ $cpuusagemaxlt4lw2title"MaxUsage($cpuusagemax%)" EOF } CpuEachCoreUsage(){ localfile=$1 sed-i's/PM//g'$file localcorenu=`cat$file|grep-v-i-E"average|system|all|linux"|sed"/^$/d"|awk'{print$2}'|sort-n-r|uniq-d|sed-n1p` #echo$corenu PLOT="" echo"">$GNUPLOTFOLDER/idle_sum.$$ for((i=0;i<=$corenu;i++)) do cat$file|grep-v-i-E"average|system|all|linux"|sed"/^$/d"|awk"(\$2==$i){print}"|awk'{print$1,"",100-$8}'>$GNUPLOTFOLDER/$i.txt localidlesum=`awk'BEGIN{total=0}{total+=$2}END{printtotal}'$GNUPLOTFOLDER/$i.txt` echo$i$idlesum>>$GNUPLOTFOLDER/idle_sum.$$ done first_load=`cat$GNUPLOTFOLDER/idle_sum.$$|sort-n-k2-r|sed-n1p|awk'{print$1}'` second_load=`cat$GNUPLOTFOLDER/idle_sum.$$|sort-n-k2-r|sed-n2p|awk'{print$1}'` third_load=`cat$GNUPLOTFOLDER/idle_sum.$$|sort-n-k2-r|sed-n3p|awk'{print$1}'` load=($first_load$second_load$third_load) echo-e"\t2.Eachcoreload:" localcpuload=("First""Second""Third") localnu=0 foriin${load[@]} do localcoreloadmax=`cat$GNUPLOTFOLDER/$i.txt|sort-n-k2-r|sed-n1p|awk'{print$2}'` localcoreloadavg=`awk'BEGIN{total=0}{total+=$2}END{printtotal/NR}'$GNUPLOTFOLDER/$i.txt` localcoreloadmin=`cat$GNUPLOTFOLDER/$i.txt|sort-n-k2|sed-n1p|awk'{print$2}'` echo-e"\t\t\tLoad${cpuload[$nu]}core$i:max=$coreloadmax,avg=$coreloadavg,min=$coreloadmin"|tee-a$REPORTFILE nu=`echo$nu+1|bc` done for((i=0;i<=corenu;i++)) do if[$i-eq$first_load];then LW=4 elif[$i-eq$second_load];then LW=3 elif[$i-eq$third_load];then LW=2 else LW=1 fi TMP1="$GNUPLOTFOLDER/$i.txt" TMP2="using1:2withllw$LW" TMP3="core$i" PLOT="$PLOT\"$TMP1\"$TMP2title\"$TMP3\"," done localtmp_ylabel_range=`cat$file|grep-v-i-E"average|system|all|linux"|sed"/^$/d"|awk'{print100-$8}'|sort-n-r|sed-n1p|awk-F"."'{print$1}'|sed-n1p` localylabel_range=`echo$tmp_ylabel_range+5|bc` /usr/local/bin/gnuplot--persist<<EOF #===============Eachcoreusage===================== settermpngsize800,600 setoutput"CpuCoreIdle.png" setkeytitle"EachCoreUsage(%)" setkeybox3 setkeybelow setylabel"CPUCoreUsage(%)" setxdatatime settimefmt"%H:%M:%S" plot[:][0:$ylabel_range]$PLOT EOF } MemoryUsage(){ localfile=$1 localtitle=`cat$file|sed'/^$/d'|grep-i-E-v"average|linux"|grep-imem` sed-i's/PM//g'$file localkbmemused=`echo$title|awk'{print$3}'` localmemused=`echo$title|awk'{print$4}'` localkbbuffers=`echo$title|awk'{print$5}'` localkbcached=`echo$title|awk'{print$6}'` localkbcommit=`echo$title|awk'{print$7}'` cat$file|sed'/^$/d'|grep-i-E-v"average|linux"|grep-i-vmem|awk'{print$1,$2/1024,($2+$3)/1024,$3/1024,$4,$5/1024,$6/1024}'>$GNUPLOTFOLDER/memory.$$ SOURCE_FILE=$GNUPLOTFOLDER/memory.$$ localmemtotal=`awk'BEGIN{total=0}{total+=$3}END{printtotal/NR}'$SOURCE_FILE` localmemusedmax=`awk'{print$4}'$SOURCE_FILE|sort-n-r|sed-n1p` localmemusedavg=`awk'BEGIN{total=0}{total+=$4}END{printtotal/NR}'$SOURCE_FILE` localmemusedmin=`awk'{print$4}'$SOURCE_FILE|sort-n|sed-n1p` localmemfreemax=`awk'{print$2}'$SOURCE_FILE|sort-n-r|sed-n1p` localmemfreeavg=`awk'BEGIN{total=0}{total+=$2}END{printtotal/NR}'$SOURCE_FILE` localmemfreemin=`awk'{print$2}'$SOURCE_FILE|sort-n|sed-n1p` localmemcachemax=`awk'{print$7}'$SOURCE_FILE|sort-n-r|sed-n1p` localmemcacheavg=`awk'BEGIN{total=0}{total+=$7}END{printtotal/NR}'$SOURCE_FILE` localmemcachemin=`awk'{print$7}'$SOURCE_FILE|sort-n|sed-n1p` localmemused_cachemax=`awk'{print$4-$7}'$SOURCE_FILE|sort-n-r|sed-n1p` localmemused_cacheavg=`awk'BEGIN{total=0}{total+=($4-$7)}END{printtotal/NR}'$SOURCE_FILE` localmemused_cachemin=`awk'{print$4-$7}'$SOURCE_FILE|sort-n|sed-n1p` localused_percent=`awk'BEGIN{total=0}{total+=$5}END{printtotal/NR}'$SOURCE_FILE` echo"`date'+%F%H:%M:%S'`:Memoryusageanalysis"|tee-a$REPORTFILE echo-e"\t\t1.totalmemory:$memtotalMB"|tee-a$REPORTFILE echo-e"\t\t2.memoryused:max=$memusedmaxMB,avg=$memusedavgMB,min=$memusedminMB"|tee-a$REPORTFILE echo-e"\t\t3.memoryfree:max=$memfreemaxMB,avg=$memfreeavgMB,min=$memfreeminMB"|tee-a$REPORTFILE echo-e"\t\t4.memorycache:max=$memcachemaxMB,avg=$memcacheavgMB,min=$memcacheminMB"|tee-a$REPORTFILE echo-e"\t\t4.memoryused-cache:max=$memused_cachemaxMB,avg=$memused_cacheavgMB,min=$memused_cacheminMB"|tee-a$REPORTFILE /usr/local/bin/gnuplot--persist<<EOF settermpngsize800,600 setoutput"MemoryUsage.png" setkeytitle"MemoryUsestate" setkeybox3 setkeybelow setylabel"MB" sety2label"(%)" setx2range[0:] sety2range[0:100] setxdatatime settimefmt"%H:%M:%S" setxtics;setx2tics;setytics;sety2tics; plot'$SOURCE_FILE'using1:3wptitle"TotalMemory",''using1:4wptitle"Used",''using1:7wptitle"Cached",\ ''using5withlltrgb"red"title"memused($used_percent%)"axisx2y2 EOF } DiskUsage(){ localfile=$1 cat$file|sed"/^$/d"|grep-v-i-E"device|linux"|sed1d>$GNUPLOTFOLDER/disk.$$ localSOURCE_FILE=$GNUPLOTFOLDER/disk.$$ plot_readiops="" plot_writeiops="" localnu=1 echo"`date'+%F%H:%M:%S'`:DiskPerformanceanalysis"|tee-a$REPORTFILE fordiskpartin`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]$"` do awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE>$GNUPLOTFOLDER/gnu_tmpfile.$diskpart plot_readiops="$plot_readiops\"$GNUPLOTFOLDER/gnu_tmpfile.$diskpart\"using4wltitle\"$diskpartreadIOPS\"," awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'BEGIN{total=0}{total+=$4}END{printtotal/NR}'>$GNUPLOTFOLDER/t.$$ localread_avg_iops=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$4}'|sort-n|sed-n1p>$GNUPLOTFOLDER/t.$$ localread_min_iops=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$4}'|sort-n-r|sed-n1p>$GNUPLOTFOLDER/t.$$ localread_max_iops=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ plot_writeiops="$plot_writeiops\"$GNUPLOTFOLDER/gnu_tmpfile.$diskpart\"using5wltitle\"$diskpartwriteIOPS\"," awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'BEGIN{total=0}{total+=$5}END{printtotal/NR}'>$GNUPLOTFOLDER/t.$$ localwrite_avg_iops=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$5}'|sort-n|sed-n1p>$GNUPLOTFOLDER/t.$$ localwrite_min_iops=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$5}'|sort-n-r|sed-n1p>$GNUPLOTFOLDER/t.$$ localwrite_max_iops=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'BEGIN{total=0}{total+=$6}END{printtotal/NR}'>$GNUPLOTFOLDER/t.$$ localavg_read_throughput=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$6}'|sort-n|sed-n1p>$GNUPLOTFOLDER/t.$$ localmin_read_throughput=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$6}'|sort-n-r|sed-n1p>$GNUPLOTFOLDER/t.$$ localmax_read_throughput=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'BEGIN{total=0}{total+=$7}END{printtotal/NR}'>$GNUPLOTFOLDER/t.$$ localavg_write_throughput=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$7}'|sort-n|sed-n1p>$GNUPLOTFOLDER/t.$$ localmin_write_throughput=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$7}'|sort-n-r|sed-n1p>$GNUPLOTFOLDER/t.$$ localmax_write_throughput=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'BEGIN{total=0}{total+=$10}END{printtotal/NR}'>$GNUPLOTFOLDER/t.$$ localavg_await=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$10}'|sort-n|sed-n1p>$GNUPLOTFOLDER/t.$$ localmin_await=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ awk"(\$1==\"$diskpart\"){print}"$SOURCE_FILE|awk'{print$10}'|sort-n-r|sed-n1p>$GNUPLOTFOLDER/t.$$ localmax_await=`cat$GNUPLOTFOLDER/t.$$` rm-f$GNUPLOTFOLDER/t.$$ echo-e"\t\t$nu.$diskpartperformance:"|tee-a$REPORTFILE echo-e"\t\t\treadiops:\t\tmax=$read_max_iops,\tavg=$read_avg_iops,\tmin=$read_min_iops"|tee-a$REPORTFILE echo-e"\t\t\twriteiops:\t\tmax=$write_max_iops,\tavg=$write_avg_iops,\tmin=$write_min_iops"|tee-a$REPORTFILE echo-e"\t\t\treaddatapersecond:\tmax=$max_read_throughputKB,\tavg=$avg_read_throughputKB,\tmin=$min_read_throughputKB"|tee-a$REPORTFILE echo-e"\t\t\twritedatapersecond:\tmax=$max_write_throughputKB,\tavg=$avg_write_throughputKB,\tmin=$min_write_throughputKB"|tee-a$REPORTFILE echo-e"\t\t\teachiowaittime:\tmax=$max_awaitms,\tavg=$avg_awaitms,\tmin=$min_awaitms"|tee-a$REPORTFILE done /usr/local/bin/gnuplot--persist<<EOF settermpngsize800,600 setoutput"DiskIOPSPerformance.png" setkeytitle"DiskIOPS" setkeybox3 setkeybelow setylabel"IOPS" plot$plot_readiops$plot_writeiops EOF } NetworkPerformance(){ localfile=$1 sed-i's/PM//g'$file cat$file|grep-E"eth|em"|grep-v-i"average">$GNUPLOTFOLDER/network_sourcefile.txt localsourcefile=$GNUPLOTFOLDER/network_sourcefile.txt localtitlerxpackage=`cat$file|grep-i"IFACE"|awk'{print$3}'|uniq-d` localtitletxpackage=`cat$file|grep-i"IFACE"|awk'{print$4}'|uniq-d` localtitlerxbyte=`cat$file|grep-i"IFACE"|awk'{print$5}'|uniq-d` localtitletxbyte=`cat$file|grep-i"IFACE"|awk'{print$6}'|uniq-d` if[$titlerxbyte=='rxkB/s'];then unit="KB" elif[$titlerxbyte=='rxbyt/s'];then unit="byte" fi localrxpackage='' localtxpackage='' localrxbyte='' localtxbyte='' localnu=1 echo"`date'+%F%H:%M:%S'`:NetworkPerformanceanalysis"|tee-a$REPORTFILE fornetcardin`cat$file|grep-E"eth|em"|grep-v-i"average"|awk'{print$2}'|sort|uniq-d` do cat$sourcefile|grep$netcard>$GNUPLOTFOLDER/gnu_network.$netcard rxpackage="$rxpackage\"$GNUPLOTFOLDER/gnu_network.$netcard\"using1:3wltitle\"$netcard$titlerxpackage\"," txpackage="$txpackage\"$GNUPLOTFOLDER/gnu_network.$netcard\"using1:4wltitle\"$netcard$titletxpackage\"," rxbyte="$rxbyte\"$GNUPLOTFOLDER/gnu_network.$netcard\"using1:5wltitle\"$netcard$titlerxbyte\"," txbyte="$txbyte\"$GNUPLOTFOLDER/gnu_network.$netcard\"using1:6wltitle\"$netcard$titletxbyte\"," max_rxpck=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-r-k3|sed-n1p|awk'{print$4}'` avg_rxpck=`awk'BEGIN{total=0}{total+=$3}END{printtotal/NR}'$GNUPLOTFOLDER/gnu_network.$netcard` min_rxpck=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-k3|sed-n1p|awk'{print$4}'` max_txpck=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-r-k4|sed-n1p|awk'{print$5}'` avg_txpck=`awk'BEGIN{total=0}{total+=$4}END{printtotal/NR}'$GNUPLOTFOLDER/gnu_network.$netcard` min_txpck=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-k4|sed-n1p|awk'{print$5}'` max_rxbyt=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-r-k5|sed-n1p|awk'{print$6}'` avg_rxbyt=`awk'BEGIN{total=0}{total+=$5}END{printtotal/NR}'$GNUPLOTFOLDER/gnu_network.$netcard` min_rxbyt=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-k5|sed-n1p|awk'{print$6}'` max_txbyt=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-r-k6|sed-n1p|awk'{print$7}'` avg_txbyt=`awk'BEGIN{total=0}{total+=$6}END{printtotal/NR}'$GNUPLOTFOLDER/gnu_network.$netcard` min_txbyt=`cat$GNUPLOTFOLDER/gnu_network.$netcard|sort-n-k6|sed-n1p|awk'{print$7}'` echo-e"\t\t$nu.$netcardload:"|tee-a$REPORTFILE echo-e"\t\t\trxpck/s:\t\tmax=$max_rxpck,\tavg=$avg_rxpck,\tmin=$min_rxpck"|tee-a$REPORTFILE echo-e"\t\t\ttxpck/s:\t\tmax=$max_txpck,\tavg=$avg_txpck,\tmin=$min_txpck"|tee-a$REPORTFILE echo-e"\t\t\trxbyt/s:\tmax=$max_rxbyt$unit,\tavg=$avg_rxbyt$unit,\tmin=$min_rxbyt$unit"|tee-a$REPORTFILE echo-e"\t\t\ttxbyt/s:\tmax=$max_txbyt$unit,\tavg=$avg_txbyt$unit,\tmin=$min_txbyt$unit"|tee-a$REPORTFILE nu=`echo$nu+1|bc` done /usr/local/bin/gnuplot--persist<<EOF settermpngsize800,600 setoutput"NetworkPackagePerformance.png" setkeytitle"networkperformance" setkeybox3 setkeybelow setylabel"Package/s" setxdatatime settimefmt"%H:%M:%S" plot$rxpackage$txpackage EOF /usr/local/bin/gnuplot--persist<<EOF settermpngsize800,600 setoutput"NetworkThougtputPerformance.png" setkeytitle"Throughputperformance" setkeybox3 setkeybelow setylabel"$unit" setxdatatime settimefmt"%H:%M:%S" plot$rxbyte$txbyte EOF } #定义gnuplot的字体msttcore目录及字体,这个在压缩包里有,放到指定目录即可。 exportGDFONTPATH="/usr/share/fonts/msttcore" exportGNUPLOT_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\tSDGAystemAnalysisReport">$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.pngCPU利用率图表 #CpuCoreIdle.png每个CPU核心的Idle #MemoryUsage.png内存使用率 #DiskIOPSPerformance.png磁盘IOPS性能 #NetworkPackagePerformance.png网卡发包率性能 #NetworkThougtputPerformance.png网卡吞吐性能 #################################################