**html
**java
[root@Cacti ~]# curl -I www.qq.com
HTTP/1.1 200 OK
Server: squid/3.4.1
Date: Wed, 08 Jul 2015 14:10:36 GMT
Content-Type: text/html; charset=GB2312
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding
Expires: Wed, 08 Jul 2015 14:11:36 GMT
Cache-Control: max-age=60
Vary: Accept-Encoding
Vary: Accept-Encoding
X-Cache: HIT from tianjin.qq.com
[root@Cacti ~]#
在開頭能夠看到該網站使用的是http協議,返回碼是200,表示OK。自動化網站監控可經過監控該返回碼進行網站狀態判斷web
o:把curl 返回的html、js 等寫到/dev/nullruby
[root@localhost ~]# curl -o /dev/null www.baidu.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 94046 0 94046 0 0 14094 0 --:--:-- 0:00:06 --:--:-- 7653k
[root@localhost ~]#
-s : 筆者測試了下彷佛是把加參數-o後顯示的內容去掉markdown
[root@localhost ~]# curl -o /dev/null -s www.baidu.com
[root@localhost ~]#
-w : 按照特定格式返回結果curl
[root@Cacti ~]# curl -o /dev/null -s -w "DNS解析時間:"%{time_namelookup}"\n" www.baidu.com
DNS解析時間:1.250
[root@Cacti ~]#
最後結合使用就能夠獲得網站響應時間了tcp
[root@localhost ~]# curl -o /dev/null -s -w "time_namelookup:"%{time_namelookup}"\n""time_connect:"%{time_connect}"\n""time_starttransfer:"%{time_starttransfer}"\n""time_total:"%{time_total}"\n""speed_download:"%{speed_download}"\n" http://www.baidu.com
time_namelookup:1.478
time_connect:1.482
time_starttransfer:1.487
time_total:1.499
speed_download:65559.000
[root@localhost ~]#
其中,
time_namelookup:DNS解析的時間;
time_connect:創建tcp使用的時間;
time_starttransfer:發出請求到網站返回數據的時間;
time_total:完成請求所用的時間;
speed_download:下載速率,單位是(字節/s)測試