(转,有改动)测试网页响应时间的shell脚本[需要curl支持]
2016-12-30 11:55
477 查看
用法及返回结果如下:
请求参数:
-n 指定发送多少次请求,默认为10
返回结果为 curl -w 选项返回值,以下摘自curl官方文档(http://curl.haxx.se/docs/manpage.html):
time_connect :连接时间,从开始到建立TCP连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个time_connect时间减去前边time_namelookup时间。(The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.)
time_namelookup: DNS解析时间,从请求开始到DNS解析完毕所用时间。(The time, in seconds, it took from the start until the name resolving was completed.)
time_total: 总时间,按秒计。精确到小数点后三位。 (The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.)
代码如下(可自行添加其他功能):
(转自:http://renxiangzyq.iteye.com/blog/782773)
[root@myserver01 tmp]# sh test_web.sh -n500 http://www.baidu.com Request url: http://www.baidu.com Request number: 500 Request Failed: 0 ------Average Value------ time_connect: 0.014414 time_namelookup: 0.010926 time_total: 0.020486 -------------------------
请求参数:
-n 指定发送多少次请求,默认为10
返回结果为 curl -w 选项返回值,以下摘自curl官方文档(http://curl.haxx.se/docs/manpage.html):
time_connect :连接时间,从开始到建立TCP连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个time_connect时间减去前边time_namelookup时间。(The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.)
time_namelookup: DNS解析时间,从请求开始到DNS解析完毕所用时间。(The time, in seconds, it took from the start until the name resolving was completed.)
time_total: 总时间,按秒计。精确到小数点后三位。 (The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.)
代码如下(可自行添加其他功能):
#!/bin/bash #requesturl.sh usage=" Usage: $0 [options...] <url>\n Options:\n -h This help text\n -n <num> The numbers to request\n " if [ $# -lt 1 ] then echo -e $usage exit 1 fi num=10 while getopts "n:h" arg do case $arg in n) num=$OPTARG if [ $num -lt 1 ] then num=1 fi ;; h) echo -e $usage exit 1 ;; ?) echo "Unknow argument" exit 1 ;; esac done url=$(eval echo "\$$#") if [ "http://" != ${url:0:7} ] then echo "The url need to add the http:// prefix" exit 1 fi echo "Request url: "$url echo "Request number: "$num i=1 while [ $i -le $num ] do c=`curl -o /dev/null -s -w \ "http_code:%{http_code} time_namelookup:%{time_namelookup} \ time_connect:%{time_connect} time_total:%{time_total}" $url` s=$s$c"\n" i=$[$i+1] done #echo -e $s echo -e $s | \ awk '{OFS="\n"}{if($1) for(i=1;i<=NF;i++)print $i}' | \ awk -F: -v num=$num -v failnum=0 \ '{if($1 != "http_code")result[$1]+=$2;if($1=="http_code" && $2 != 200)failnum++} \ END{print "Request Failed: " failnum "\n------Average Value------"; \ for(i in result) {print i ": " result[i]/num;} \ print "-------------------------"}'
(转自:http://renxiangzyq.iteye.com/blog/782773)
相关文章推荐
- curl测试网页响应时间
- Linux中用curl命令来测试网页响应时间
- Curl测试网页响应时间
- Curl测试网页响应时间(转载)
- 用curl命令来测试网页响应时间
- 用curl命令来测试网页响应时间
- linux下利用curl监控网页shell脚本
- 配置Apache2.x 支持shell脚本和Python编写CGI程序+测试程序
- 亿能测试大讲堂 - YY在线课程[ 测试人员需要掌握的Shell脚本编程 ]
- 用curl测试网站响应时间
- curl 测试web站点的响应时间
- curl 命令,curl监控网页shell脚本,curl多进程实现并控制进程数
- mysql触发器内执行shell脚本,shell脚本用curl访问php网页
- curl命令测试网络请求中DNS解析、响应时间
- python脚本测试网站响应时间
- curl 命令,curl监控网页shell脚本,curl多进程实现并控制进程数
- 亿能测试大讲堂 - YY在线课程[ 测试人员需要掌握的Shell脚本编程 ]
- 测试一个域名DNS查询时间的shell脚本
- linux下利用curl监控网页shell脚本
- 【shell】推荐一份写测试shell脚本不错的资料