如何使用GNUPlot从ApacheBench输出文件绘制响应时间直方图?
我正在对我正在构建的网站进行一些基准测试,并希望生成响应时间图。以下是我的ApacheBench用法:如何使用GNUPlot从ApacheBench输出文件绘制响应时间直方图?,gnuplot,histogram,apachebench,Gnuplot,Histogram,Apachebench,我正在对我正在构建的网站进行一些基准测试,并希望生成响应时间图。以下是我的ApacheBench用法: > ab -n 100 -c 10 -g foo.tsv http://foo/ 这给了我一个TSV文件,其中包含如下数据: starttime seconds ctime dtime ttime wait Tue Dec 03 16:24:53 2013 1386087893 2 413
> ab -n 100 -c 10 -g foo.tsv http://foo/
这给了我一个TSV文件,其中包含如下数据:
starttime seconds ctime dtime ttime wait
Tue Dec 03 16:24:53 2013 1386087893 2 413 415 367
Tue Dec 03 16:24:49 2013 1386087889 1 468 469 452
Tue Dec 03 16:24:54 2013 1386087894 9 479 488 446
Tue Dec 03 16:24:49 2013 1386087889 1 497 498 437
Tue Dec 03 16:24:54 2013 1386087894 33 465 498 458
Tue Dec 03 16:24:53 2013 1386087893 1 507 508 506
Tue Dec 03 16:24:51 2013 1386087891 0 544 544 512
我想将这些数据转换成直方图,Y轴上显示数量,X轴上显示响应时间(ttime)
我的绘图脚本如下,但我得到的只是一个空(零字节)jpeg文件
clear
reset
set output "out.jpg"
# Select histogram data
set style data histogram
set style fill solid border
plot 'foo.tsv' using 5
exit
如何生成此直方图
奖金问题。我意识到这些数据可能会导致一次或两次点击产生许多数据点,因此我如何将TTI时间四舍五入到(比如)最接近的10毫秒,以减少每次点击次数较多的数据点?以下几点:
jpg
文件,必须先使用set terminal jpeg
。但无论如何,如果您需要位图图像,我建议您使用pngcairo
终端tsv
使用选项卡作为列分隔符。默认情况下,gnuplot使用任何空白字符作为分隔符,在这种情况下,第五列总是2013
。因此,请使用设置数据文件分隔符'\t'
平滑频率
,用于装箱x值。作为y值,我使用1
,因此平滑频率
只需向上计数every::1
跳过数据文件的第一行框
打印样式:设置终端pngcairo
设置输出“foo.png”
设置数据文件分隔符“\t”
设置填充实体边框的样式
将箱宽设置为8绝对值
设置Y范围[0:]
箱子(x)=10*层(x/10.0)
使用(bin($5)):(1)每隔::1平滑频率绘制“foo.tsv”,方框标题为“ttime”
将其复制到.p文件中
touch foo.p
gedit foo.p
现在将这些数据粘贴到该文件并保存
# output as png image
set terminal png
# save file to "benchmark.png"
set output "benchmark.png"
# graph a title
set title "ab -n 100 -c 10 -g foo.tsv http://foo/"
# nicer aspect ratio for image size
set size 1,0.7
# y-axis grid
set grid y
# x-axis label
set xlabel "request"
# y-axis label
set ylabel "response time (ms)"
# plot data from "foo.tsv" using column 9 with smooth sbezier lines
plot "foo.tsv" using 9 smooth sbezier with lines title "server1:"
现在通过以下方式生成foo.p的绘图文件:
gnuplot foo.p
我总结了这个脚本中的所有内容:
#!/bin/bash
#URL to test
URL_ATAQUE="http://foo.bar"
#Results file
FICH_RESULT="resultados.tsv"
#Plot
IMAGEN_RESULT="grafica.png"
echo -e "Executing bench on $URL_ATAQUE\nPlease, wait..."
#Sintaxis:
#-n = Number of requests
#-c = simult. connections
#-g = output file
ab -n 5 -c 1 -g $FICH_RESULT $URL_ATAQUE
touch $FICH_RESULT
echo "set terminal png" > plot
echo "set output \"$IMAGEN_RESULT\"" >>plot
echo "set title \"$URL_ATAQUE\"" >>plot
echo "set size 1,0.7" >>plot
echo "set grid y" >> plot
echo "set xlabel \"Request\"" >> plot
echo "set ylabel \"Response time (ms)\"" >> plot
echo "plot \"$FICH_RESULT\" using 9 smooth sbezier with lines title \"server1:\"" >>plot
gnuplot plot
rm plot
rm $FICH_RESULT
gnome-open $IMAGEN_RESULT
#USE BELOW IF NOT IN GNOME
#xdg-open $IMAGEN_RESULT
如果需要,只需chmod+x并使用./fileName运行我已经为apachebench结果打印开发了一套更完整的助手脚本,包括多个测试结果的合并,您可以查看它们。实际上很难判断是否需要every::1。您确定gnuplot没有自动忽略.tsv文件第一行上的文本吗?@netpothina我知道,绘制直方图时标题行有问题,请参阅例如。当我用盒子密谋的时候,我不确定这个案子。这就是我写“可能”的原因。然而,这似乎确实是没有必要的。我真的不知道为什么这个答案被否决了,它给了我我一直在寻找的解决方案。谢谢