编写Bash Shell通过gnuplot绘制系统性能数据图的方法
程序员文章站
2022-05-24 13:02:12
使用步骤:
1.设置一个定时任何 执行getperf.sh,采集性能数据
2.将采集到性能数据文件,如:192.168.1.1.tar.gz 解压
3.将性能分析的脚...
使用步骤:
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
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/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 "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" ];then sysip=$pri_ip else sysip=$pub_ip fi if [ -d $pwd/$sysip ];then rm -rf $pwd/$sysip fi mkdir -p $pwd/$sysip if ! grep iostat /usr/bin/iostat ;then yum -y install sysstat fi } 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++)) 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 tar zcvf $sysip.tar.gz $sysip fi
performance_analyse.sh脚本内容如下:
################################################# # # 这个脚本的作用是处理由性能采集脚本收集到的性能数据 #然后使用gunplot生产直观的性能图。 # ################################################# #!/bin/bash sysinfo(){ local file=$1 local 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 $reportfile echo "ip address:"|tee -a $reportfile echo -e "$ipaddr"|tee -a $reportfile echo "$productname" |tee -a $reportfile echo -e "\t$cpumodel" |tee -a $reportfile echo -e "\tcpu cores\t:$cpucore"|tee -a $reportfile echo -e "\t$cpumhz"|tee -a $reportfile echo -e "\tphysical cpu number:$physical"|tee -a $reportfile echo -e "\teach cpu real core:$realcpucore"|tee -a $reportfile echo "$diskpart"|tee -a $reportfile echo -e "memory(mb):\n$memory"|tee -a $reportfile } cpuallusage(){ local file=$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"|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 $reportfile echo -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=$1 sed -i 's/pm//g' $file local 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 $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 local idlesum=`awk 'begin{total=0}{total+=$2}end{print total}' $gnuplotfolder/$i.txt` echo $i $idlesum >>$gnuplotfolder/idle_sum.$$ done first_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=0 for i in ${load[@]} do local 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 $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="using 1:2 with l lw $lw" tmp3="core $i " plot="$plot \"$tmp1\" $tmp2 title \"$tmp3\"," done local 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=$1 local title=`cat $file |sed '/^$/d'|grep -i -e -v "average|linux"|grep -i mem` sed -i 's/pm//g' $file local 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 $reportfile echo -e "\t\t1.total memory: $memtotal mb"|tee -a $reportfile echo -e "\t\t2.memory used: max=$memusedmax mb ,avg=$memusedavg mb ,min=$memusedmin mb"|tee -a $reportfile echo -e "\t\t3.memory free: max=$memfreemax mb ,avg=$memfreeavg mb ,min=$memfreemin mb"|tee -a $reportfile echo -e "\t\t4.memory cache: max=$memcachemax mb ,avg=$memcacheavg mb ,min=$memcachemin mb"|tee -a $reportfile echo -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=$1 cat $file |sed "/^$/d"|grep -v -i -e "device|linux"|sed 1d >$gnuplotfolder/disk.$$ local source_file=$gnuplotfolder/disk.$$ plot_readiops="" plot_writeiops="" local nu=1 echo "`date '+%f %h:%m:%s'`: disk performance analysis" |tee -a $reportfile for 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]$"` do awk "(\$1==\"$diskpart\"){print}" $source_file >$gnuplotfolder/gnu_tmpfile.$diskpart plot_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 $reportfile echo -e "\t\t\t read iops:\t\t max=$read_max_iops ,\t avg=$read_avg_iops ,\t min=$read_min_iops"|tee -a $reportfile echo -e "\t\t\t write iops:\t\t max=$write_max_iops ,\t avg=$write_avg_iops ,\t min=$write_min_iops"|tee -a $reportfile echo -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 $reportfile echo -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 $reportfile echo -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 $reportfile done /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=$1 sed -i 's/pm//g' $file cat $file |grep -e "eth|em"|grep -v -i "average">$gnuplotfolder/network_sourcefile.txt local sourcefile=$gnuplotfolder/network_sourcefile.txt local 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' ];then unit="kb" elif [ $titlerxbyte == 'rxbyt/s' ];then unit="byte" fi local rxpackage='' local txpackage='' local rxbyte='' local txbyte='' local nu=1 echo "`date '+%f %h:%m:%s'`: network performance analysis" |tee -a $reportfile for netcard in `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\" 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 $reportfile echo -e "\t\t\t rxpck/s:\t\t max=$max_rxpck ,\t avg=$avg_rxpck ,\t min=$min_rxpck"|tee -a $reportfile echo -e "\t\t\t txpck/s:\t\t max=$max_txpck ,\t avg=$avg_txpck ,\t min=$min_txpck"|tee -a $reportfile echo -e "\t\t\t rxbyt/s:\t max=$max_rxbyt $unit,\t avg=$avg_rxbyt $unit,\t min=$min_rxbyt $unit"|tee -a $reportfile echo -e "\t\t\t txbyt/s:\t max=$max_txbyt $unit,\t avg=$avg_txbyt $unit,\t min=$min_txbyt $unit"|tee -a $reportfile nu=`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 网卡吞吐性能 #################################################
上一篇: Shell脚本实现判断IP地址是否在一个ip段内代码分享
下一篇: 镇场子很不错