curl 分析 http 請求 rt時間延遲


curl 分析 http 請求 rt時間延遲

20190905 Chenxin

curl發送post請求,統計各階段的響應時間(rt值,response time)

命令格式

curl -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n" -d  "param1=value1&param2=value2" "http://47.56.108.137:8080/index"
或
curl -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n" "http://47.56.108.137:8080/index"
或(推薦)
curl -o /dev/null -s -w 'time_namelookup: %{time_namelookup}\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n' 47.56.108.137:8080/index #每個解釋一個換行.

或(推薦)
curl -o /dev/null -s -w 'time_namelookup: %{time_namelookup}\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n' www.baidu.com

-o:把curl返回的html,js寫到/dev/null
-s:去掉所有狀態
-w:按照后面的格式寫出rt
time_namelookup: DNS 解析域名[www.taobao.com]的時間
time_commect: client和server端建立TCP 連接的時間
time_starttransfer: 從client發出請求;到web的server 響應第一個字節的時間
time_total: client發出請求;到web的server發送會所有的相應數據的時間
speed_download: 下載速度 單位 byte/s
\n: 輸出結果后回車(后面無需空格,加空格也可以)

結果

0.005096::0.045880::0.089548::0.089726::144.000
time_namelookup  time_commect    time_starttransfer      time_total     speed_download
DNS             tcp建立連接         server響應第一個字節    server返回所有數據    下載速度
這里可以優化(用IP)  物理距離導致(40ms)   服務器處理時間(45ms)    服務器處理時間(幾乎0ms) 帶寬

針對以上時間,比如第二列時間,是包含了第一列的時間的.

curl其他典型示例

等待以后慢慢添加

curl參數解析.以下部分可以不看(為指令自身參數說明,請通過指令自身輸出查看)

  • 完整參數
    curl --help

  • 指令與參數解析
    curl --manual
    包含了 -w 的各個子參數解析說明

-w, --write-out <format>
              Make curl display information on stdout after a completed trans-
              fer. The format is a string that may contain  plain  text  mixed
              with  any  number of variables. The format can be specified as a
              literal "string", or you can have curl read the  format  from  a
              file  with  "@filename" and to tell curl to read the format from
              stdin you write "@-".

              The variables present in the output format will  be  substituted
              by  the  value or text that curl thinks fit, as described below.
              All variables are specified as %{variable_name} and to output  a
              normal  % you just write them as %%. You can output a newline by
              using \n, a carriage return with \r and a tab space with \t.

              NOTE: The %-symbol is a special symbol in the win32-environment,
              where  all  occurrences  of  %  must  be doubled when using this
              option.

              The variables available are:

              content_type   The Content-Type of the  requested  document,  if
                             there was any.

              filename_effective
                             The  ultimate  filename  that curl writes out to.
                             This is only meaningful if curl is told to  write
                             to  a  file  with  the  -O,  --remote-name or -o,
                             --output option. It's most useful in  combination
                             with  the -J, --remote-header-name option. (Added
                             in 7.26.0)

              ftp_entry_path The initial path curl ended up in when logging on
                             to the remote FTP server. (Added in 7.15.4)

              http_code      The numerical response code that was found in the
                             last retrieved HTTP(S)  or  FTP(s)  transfer.  In
                             7.18.2  the alias response_code was added to show
                             the same info.

              http_connect   The numerical code that was  found  in  the  last
                             response   (from  a  proxy)  to  a  curl  CONNECT
                             request. (Added in 7.12.4)

              http_version   The  http  version  that  was  effectively  used.
                             (Added in 7.50.0)

              local_ip       The  IP  address  of  the  local  end of the most
                             recently done connection - can be either IPv4  or
                             IPv6 (Added in 7.29.0)

              local_port     The  local  port number of the most recently done
                             connection (Added in 7.29.0)

              num_connects   Number of new connects made in the recent  trans-
                             fer. (Added in 7.12.3)

              num_redirects  Number  of  redirects  that  were followed in the
                             request. (Added in 7.12.3)

              proxy_ssl_verify_result
                             The result of the HTTPS proxy's SSL peer certifi-
                             cate verification that was requested. 0 means the
                             verification was successful. (Added in 7.52.0)

              redirect_url   When an HTTP request was made without -L to  fol-
                             low redirects, this variable will show the actual
                             URL a redirect  would  take  you  to.  (Added  in
                             7.18.2)

              remote_ip      The  remote  IP address of the most recently done
                             connection - can be either IPv4 or IPv6 (Added in
                             7.29.0)

              remote_port    The  remote port number of the most recently done
                             connection (Added in 7.29.0)

              scheme         The URL scheme (sometimes called  protocol)  that
                             was effectively used (Added in 7.52.0)

              size_download  The total amount of bytes that were downloaded.

              size_header    The total amount of bytes of the downloaded head-
                             ers.

              size_request   The total amount of bytes that were sent  in  the
                             HTTP request.

              size_upload    The total amount of bytes that were uploaded.

              speed_download The average download speed that curl measured for
                             the complete download. Bytes per second.

              speed_upload   The average upload speed that curl  measured  for
                             the complete upload. Bytes per second.

              ssl_verify_result
                             The  result of the SSL peer certificate verifica-
                             tion that was requested. 0 means the verification
                             was successful. (Added in 7.19.0)

              time_appconnect
                             The  time,  in  seconds,  it  took from the start
                             until the SSL/SSH/etc  connect/handshake  to  the
                             remote host was completed. (Added in 7.19.0)

              time_connect   The  time,  in  seconds,  it  took from the start
                             until the TCP connect  to  the  remote  host  (or
                             proxy) was completed.

              time_namelookup
                             The  time,  in  seconds,  it  took from the start
                             until the name resolving was completed.

              time_pretransfer
                             The time, in seconds,  it  took  from  the  start
                             until  the file transfer was just about to begin.
                             This includes all pre-transfer commands and nego-
                             tiations that are specific to the particular pro-
                             tocol(s) involved.

              time_redirect  The time, in seconds, it took for all redirection
                             steps including name lookup, connect, pretransfer
                             and transfer before  the  final  transaction  was
                             started.  time_redirect shows the complete execu-
                             tion time for multiple  redirections.  (Added  in
                             7.12.3)

              time_starttransfer
                             The  time,  in  seconds,  it  took from the start
                             until the first byte was just about to be  trans-
                             ferred.  This  includes time_pretransfer and also
                             the time  the  server  needed  to  calculate  the
                             result.

              time_total     The  total time, in seconds, that the full opera-
                             tion lasted.

              url_effective  The URL that was fetched last. This is most mean-
                             ingful  if  you've  told curl to follow location:
                             headers.

              If this option is used several times, the last one will be used.


  • 常用參數
-A/--user-agent <string>              設置用戶代理發送給服務器
-b/--cookie <name=string/file>    cookie字符串或文件讀取位置
-c/--cookie-jar <file>                    操作結束后把cookie寫入到這個文件中
-C/--continue-at <offset>            斷點續轉
-D/--dump-header <file>              把header信息寫入到該文件中
-e/--referer                                  來源網址
-f/--fail                                          連接失敗時不顯示http錯誤
-o/--output                                  把輸出寫到該文件中
-O/--remote-name                      把輸出寫到該文件中,保留遠程文件的文件名
-r/--range <range>                      檢索來自HTTP/1.1或FTP服務器字節范圍
-s/--silent                                    靜音模式。不輸出任何東西
-T/--upload-file <file>                  上傳文件
-u/--user <user[:password]>      設置服務器的用戶和密碼
-w/--write-out [format]                什么輸出完成后
-x/--proxy <host[:port]>              在給定的端口上使用HTTP代理
-#/--progress-bar                        進度條顯示當前的傳送狀態

其他參數

-a/--append                        上傳文件時,附加到目標文件
--anyauth                            可以使用“任何”身份驗證方法
--basic                                使用HTTP基本驗證
-B/--use-ascii                      使用ASCII文本傳輸
-d/--data <data>                  HTTP POST方式傳送數據
--data-ascii <data>            以ascii的方式post數據
--data-binary <data>          以二進制的方式post數據
--negotiate                          使用HTTP身份驗證
--digest                        使用數字身份驗證
--disable-eprt                  禁止使用EPRT或LPRT
--disable-epsv                  禁止使用EPSV
--egd-file <file>              為隨機數據(SSL)設置EGD socket路徑
--tcp-nodelay                  使用TCP_NODELAY選項
-E/--cert <cert[:passwd]>      客戶端證書文件和密碼 (SSL)
--cert-type <type>              證書文件類型 (DER/PEM/ENG) (SSL)
--key <key>                    私鑰文件名 (SSL)
--key-type <type>              私鑰文件類型 (DER/PEM/ENG) (SSL)
--pass  <pass>                  私鑰密碼 (SSL)
--engine <eng>                  加密引擎使用 (SSL). "--engine list" for list
--cacert <file>                CA證書 (SSL)
--capath <directory>            CA目   (made using c_rehash) to verify peer against (SSL)
--ciphers <list>                SSL密碼
--compressed                    要求返回是壓縮的形勢 (using deflate or gzip)
--connect-timeout <seconds>    設置最大請求時間
--create-dirs                  建立本地目錄的目錄層次結構
--crlf                          上傳是把LF轉變成CRLF
--ftp-create-dirs              如果遠程目錄不存在,創建遠程目錄
--ftp-method [multicwd/nocwd/singlecwd]    控制CWD的使用
--ftp-pasv                      使用 PASV/EPSV 代替端口
--ftp-skip-pasv-ip              使用PASV的時候,忽略該IP地址
--ftp-ssl                      嘗試用 SSL/TLS 來進行ftp數據傳輸
--ftp-ssl-reqd                  要求用 SSL/TLS 來進行ftp數據傳輸
-F/--form <name=content>        模擬http表單提交數據
-form-string <name=string>      模擬http表單提交數據
-g/--globoff                    禁用網址序列和范圍使用{}和[]
-G/--get                        以get的方式來發送數據
-h/--help                      幫助
-H/--header <line>              自定義頭信息傳遞給服務器
--ignore-content-length        忽略的HTTP頭信息的長度
-i/--include                    輸出時包括protocol頭信息
-I/--head                      只顯示文檔信息
-j/--junk-session-cookies      讀取文件時忽略session cookie
--interface <interface>        使用指定網絡接口/地址
--krb4 <level>                  使用指定安全級別的krb4
-k/--insecure                  允許不使用證書到SSL站點
-K/--config                    指定的配置文件讀取
-l/--list-only                  列出ftp目錄下的文件名稱
--limit-rate <rate>            設置傳輸速度
--local-port<NUM>              強制使用本地端口號
-m/--max-time <seconds>        設置最大傳輸時間
--max-redirs <num>              設置最大讀取的目錄數
--max-filesize <bytes>          設置最大下載的文件總量
-M/--manual                    顯示全手動
-n/--netrc                      從netrc文件中讀取用戶名和密碼
--netrc-optional                使用 .netrc 或者 URL來覆蓋-n
--ntlm                          使用 HTTP NTLM 身份驗證
-N/--no-buffer                  禁用緩沖輸出
-p/--proxytunnel                使用HTTP代理
--proxy-anyauth                選擇任一代理身份驗證方法
--proxy-basic                  在代理上使用基本身份驗證
--proxy-digest                  在代理上使用數字身份驗證
--proxy-ntlm                    在代理上使用ntlm身份驗證
-P/--ftp-port <address>        使用端口地址,而不是使用PASV
-Q/--quote <cmd>                文件傳輸前,發送命令到服務器
--range-file                    讀取(SSL)的隨機文件
-R/--remote-time                在本地生成文件時,保留遠程文件時間
--retry <num>                  傳輸出現問題時,重試的次數
--retry-delay <seconds>        傳輸出現問題時,設置重試間隔時間
--retry-max-time <seconds>      傳輸出現問題時,設置最大重試時間
-S/--show-error                顯示錯誤
--socks4 <host[:port]>          用socks4代理給定主機和端口
--socks5 <host[:port]>          用socks5代理給定主機和端口
-t/--telnet-option <OPT=val>    Telnet選項設置
--trace <file>                  對指定文件進行debug
--trace-ascii <file>            Like --跟蹤但沒有hex輸出
--trace-time                    跟蹤/詳細輸出時,添加時間戳
--url <URL>                    Spet URL to work with
-U/--proxy-user <user[:password]>  設置代理用戶名和密碼
-V/--version                    顯示版本信息
-X/--request <command>          指定什么命令
-y/--speed-time                放棄限速所要的時間。默認為30
-Y/--speed-limit                停止傳輸速度的限制,速度時間'秒
-z/--time-cond                  傳送時間設置
-0/--http1.0                    使用HTTP 1.0
-1/--tlsv1                      使用TLSv1(SSL)
-2/--sslv2                      使用SSLv2的(SSL)
-3/--sslv3                      使用的SSLv3(SSL)
--3p-quote                      like -Q for the source URL for 3rd party transfer
--3p-url                        使用url,進行第三方傳送
--3p-user                      使用用戶名和密碼,進行第三方傳送
-4/--ipv4                      使用IP4
-6/--ipv6                      使用IP6


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM