五、生成图表
首先写一个脚本获取数据源:
# cat tpcc-output-analyze.sh
#!/bin/sh
TIMESLOT=1
if [ -n "$2" ]
then
TIMESLOT=$2
fi
cat $1 | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=$TIMESLOT 'BEGIN { FS="[,():]"; s=0; cntr=0; aggr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } if ( cntr==timeslot ) { printf ("%d %3d\n",$1,(aggr/timeslot)) ; cntr=0; aggr=0 } }'
# cat tpcc-output-analyze.sh
#!/bin/sh
TIMESLOT=1
if [ -n "$2" ]
then
TIMESLOT=$2
fi
cat $1 | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=$TIMESLOT 'BEGIN { FS="[,():]"; s=0; cntr=0; aggr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } if ( cntr==timeslot ) { printf ("%d %3d\n",$1,(aggr/timeslot)) ; cntr=0; aggr=0 } }'
这个脚本就是对 tpcc-output-nobinlog 的第一列与第二列进行运算。
#./tpcc-output-analyze.sh tpcc-output-nobinlog > tpcc-graphic-data.txt
绘图过程:
#cat log.conf
set terminal gif small size 480,360 #指定输出成gif图片,且图片大小为550×25
set output "tcpp.gif" #指定输出gif图片的文件名
set title "MySQL Performance" #图片标题
set style data lines #显示网格
set xlabel "Time/s" #X轴标题
set ylabel "Data" #Y轴标题
set grid #显示网格
plot \
"tpcc-graphic-data.txt" using 1:2 title "Total throughput" with lines #从tpcc-graphic-data.txt文件中读取第一列和第二列作为X轴和Y轴数据,示例名"Total throughput"
#cat log.conf
set terminal gif small size 480,360 #指定输出成gif图片,且图片大小为550×25
set output "tcpp.gif" #指定输出gif图片的文件名
set title "MySQL Performance" #图片标题
set style data lines #显示网格
set xlabel "Time/s" #X轴标题
set ylabel "Data" #Y轴标题
set grid #显示网格
plot \
"tpcc-graphic-data.txt" using 1:2 title "Total throughput" with lines #从tpcc-graphic-data.txt文件中读取第一列和第二列作为X轴和Y轴数据,示例名"Total throughput"
运行生成tcpp.gif:
#cat log.conf | gnuplot
示例:
补充gnuplot绘图,详细可以google下
例如得到文件类似如下:
11:23 28 15
11:24 10 7
11:25 224 37 13
11:26 470 192
11:27 344 187 1
11:28 441 77 2
11:29 419 8
然后创建gnuplot.conf如下:
set terminal png xFFEEDD size 2048,512
set output "log.png"
set autoscale
set xdata time
set timefmt "%H:%M"
set format x "%H:%M"
set xtics 10
set mxtics 4
set style data lines
set datafile missing "0″
set xlabel "time per day"
set ylabel "purge"
set title "DPD expires"
set grid
plot "log" using 1:2 title "html/min","log" using 1:3 title "js/min","log" using 1:4 title "css/min"
运行cat gnuplot.conf|gnuplot就得到log.png了,如下:

参考文章:http://www.linuxidc.com/Linux/2014-03/98563.htm
