zoukankan      html  css  js  c++  java
  • linux运维笔记——curl

    **

    1、获取网站返回码

    **

    [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。自动化网站监控可通过监控该返回码进行网站状态判断

    2、通过curl获取web网站的响应时间,相关参数说明:

    o:把curl 返回的html、js 等写到/dev/null

    [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后显示的内容去掉

    [root@localhost ~]# curl -o /dev/null -s www.baidu.com
    [root@localhost ~]# 

    -w : 按照特定格式返回结果

    [root@Cacti ~]# curl -o /dev/null -s -w "DNS解析时间:"%{time_namelookup}"
    " www.baidu.com
    DNS解析时间:1.250
    [root@Cacti ~]#

    最后结合使用就可以得到网站响应时间了

    [root@localhost ~]# curl -o /dev/null -s -w "time_namelookup:"%{time_namelookup}"
    ""time_connect:"%{time_connect}"
    ""time_starttransfer:"%{time_starttransfer}"
    ""time_total:"%{time_total}"
    ""speed_download:"%{speed_download}"
    " 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)

  • 相关阅读:
    nginx 自启动脚本
    debian开机启动管理
    vagrant up connection time out
    vagrant在windows下的使用
    Office Web Apps Server
    邻接表模型中的节点移动
    Managing Hierarchical Data in MySQL(邻接表模型)[转载]
    play mp3 in c#
    2014年5月份第3周51Aspx源码发布详情
    2014年5月份第2周51Aspx源码发布详情
  • 原文地址:https://www.cnblogs.com/dengtr/p/5027363.html
Copyright © 2011-2022 走看看