获取网站性能指标shell脚本
来源:互联网 发布:程序员培训全日制吗 编辑:程序博客网 时间:2024/04/30 02:19
本文转载自http://pmghong.blog.51cto.com/3221425/1390599。
1.web主要性能指标
2.curl命令介绍
1
root@node1:~
# curl -o /dev/null -s -w %{time_total}"\n" www.yy.com
1
2
3
4
5
root@node1:~
# curl -o /dev/null -w %{time_namelookup}"\n" www.yy.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 148k 0 148k 0 0 503k 0 --:--:-- --:--:-- --:--:-- 536k
0.006
//
最后这个值才是我们要的
3.获取网站性能脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
usage="
Usage: $0 [options...] <url>\n
Options:\n
-h Show this help message.\n
-u <url> The url to request.\n
-n <num> The numbers to request\n
"
if
[ $
# -lt 4 ];then
echo
-e $usage
exit
1
fi
num=10
while
getopts
"n:h:u"
arg
do
case
$arg
in
n)
num=$2
if
[ $num -lt 1 ];
then
num=1
fi
;;
h)
echo
-e $usage
exit
1
;;
u)
url=$4
;;
*)
echo
"Unkown argument"
exit
1
;;
esac
done
echo
"Request url:"
${url}
echo
"Request number:"
${num}
echo
"------Average Value------"
[ -d
"/tmp/data"
] ||
mkdir
-p
/tmp/data
options=
"time_total time_connect time_redirect time_namelookup time_pretransfer time_starttransfer"
for
option
in
$options
do
for
((i=1;i<=${num};i++))
do
curl -o
/dev/null
-s -w %{$option}
"\n"
$url >>
/tmp/data/
$option
done
avg=`
awk
'BEGIN{sum=0;NR=0}{sum+=$1}END{print sum/NR}'
/tmp/data/
$option`
echo
${option}
" = "
${avg}
cat
/dev/null
>
/tmp/data/
$option
done
1
2
3
4
5
6
7
8
9
10
root@node1:
/tmp/shell
# ./url.sh -n 5 -u www.yy.com
Request url: www.yy.com
Request number: 5
------Average Value------
time_total = 0.541
time_connect = 0.0296
time_redirect = 0
time_namelookup = 0.0054
time_pretransfer = 0.0268
time_starttransfer = 0.0452
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
usage="
Usage: $0 [options...] <url>\n
Options:\n
-h Show this help message.\n
-u <url> The url to request.\n
-n <num> The numbers to request\n
"
echo
-e $usage
exit
1
fi
num=10
while
getopts
"n:h:u"
arg
do
case
$arg
in
n)
num=$2
if
[ $num -lt 1 ];
then
num=1
fi
;;
h)
echo
-e $usage
exit
1
;;
u)
url=$4
;;
*)
echo
"Unkown argument"
exit
1
;;
esac
done
echo
"Request url:"
${url}
echo
"Request number:"
${num}
echo
"------Average Value------"
#定义输出文件、需要获取的指标
outputfile=
"/tmp/data/requestdata.txt"
[ -d
"/tmp/data"
] ||
mkdir
-p
/tmp/data
options=
"%{time_total} %{time_connect} %{time_redirect} %{time_namelookup} %{time_pretransfer} %{time_starttransfer}\n"
#执行n次curl,获取n个数据
for
((i=1;i<=${num};i++))
do
curl -o
/dev/null
-s -w
"$options"
$url >> $outputfile
done
#计算平均值并输出
awk
'BEGIN{tt=0;tc=0;
tr
=0;tn=0;tp=0;ts=0}{tt+=$1;tc+=$2;
tr
+=$3;tn+=$4;tp+=$5;ts+=$6}\
END{print \
" time_total = "
tt
/NR
"\n"
,\
"time_connect = "
tc
/NR
"\n"
,\
"time_redirect = "
tr
/NR
"\n"
,\
"time_namelookup = "
tn
/NR
"\n"
,\
"time_pretransfer = "
tp
/NR
"\n"
,\
"time_starttransfer = "
ts
/NR
"\n"
}' $outputfile
cat
/dev/null
> $outputfile
1
2
3
4
5
6
7
8
9
10
root@node1:
/tmp/shell
# ./url.sh -n 10 -u www.yy.com
Request url: www.yy.com
Request number: 10
------Average Value------
time_total = 0.2569
time_connect = 0.0279
time_redirect = 0
time_namelookup = 0.0058
time_pretransfer = 0.0279
time_starttransfer = 0.0569
1
2
3
#每分钟获取一次数据
root@node1:~
# crontab –e
* * * * * curl –o
/dev/null
–s –w %{time_connect} www.yy.com >>
/tmp/data/data_collected
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
outputfile=
"/tmp/data/data_collected"
awk
'BEGIN{tt=0;tc=0;
tr
=0;tn=0;tp=0;ts=0}{tt+=$1;tc+=$2;
tr
+=$3;tn+=$4;tp+=$5;ts+=$6}\
END{print \
" time_total = "
tt
/NR
"\n"
,\
"time_connect = "
tc
/NR
"\n"
,\
"time_redirect = "
tr
/NR
"\n"
,\
"time_namelookup = "
tn
/NR
"\n"
,\
"time_pretransfer = "
tp
/NR
"\n"
,\
"time_starttransfer = "
ts
/NR
"\n"
}' $outputfile
cat
/dev/null
> $outputfile
0 0
- 获取网站性能指标shell脚本
- 网站性能指标
- shell脚本使用curl获取访问网站的状态码
- shell脚本学习网站
- shell脚本获取选项
- shell脚本学习的网站
- web网站性能指标
- Linux Shell脚本获取文件大小
- shell脚本获取CPU使用率
- shell脚本获取当前脚本所在位置
- Ruby脚本获取网站内容
- 获取shell脚本自身所在目录的Shell脚本分享
- shell 监控网站是否异常的脚本
- shell脚本-实现网站自动登录
- Shell 命令--网站--总结自《Linux Shell 脚本攻略》
- linuxC程序中获取shell脚本输出
- 获取所有本地用户power shell 脚本
- C++ 中获取shell脚本返回值
- Cocoapods 卸载,重装,更新版本,(本人亲测)
- 内存优化个人总结
- BZOJ3993 星际战争 题解(二分+最大流)
- 高仿IOS 提示框
- unity 绘制面
- 获取网站性能指标shell脚本
- ASP.NET如何定时调用WebService服务
- 面向对象编程
- innodb_flush_method
- 面试题-----两个栈实现一个队列
- RecyclerView存在大量Item时,当滚到底部时快速滑到顶部
- Qt Creator 管理多工程的实践
- 20170314
- house robber