curl命令檢視響應時間

oktokeep發表於2024-05-22

curl命令檢視響應時間

curl -w "%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}" -X GET "http://IP地址+埠/?引數"
curl -w "%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}" -X POST -H "Content-Type: application/json" -d '{"test1":"hah","test2":"qwe","test3":"111"}' "http://IP地址+埠/?引數"

引數				含義
time_namelookup		DNS解析域名時間
time_connect		TCP連線的時間,三次握手的時間
time_starttransfer	從請求開始到第一個位元組將要傳輸的時間
time_total			總時間
speed_download		下載速度,單位-位元組每秒
time_appconnect		SSL|SSH等上層連線建立的時間
time_pretransfer	從請求開始到響應開始傳輸的時間
time_redirect		從開始到最後一個請求事務的時間

Curl請求示例
curl -X GET "http://<host:port>/api/1/test/get?test=<value>&app_id=<app_id>&sign=<sign>&timestamp=<timestamp>"
curl -X POST -H "Content-Type: application/json" -d '{"test1":"hah","test2":"qwe","test3":"111"}' "http://<host:port>/api/1/test/post2?test=<value>&app_id=<app_id>&sign=<sign>&timestamp=<timestamp>"

demo請求示例:
curl -w "%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}::%{time_appconnect}::%{time_pretransfer}::%{time_redirect}" -X GET "http://www.baidu.com"

列印輸出:

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新聞</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地圖</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>影片</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>貼吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登入</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登入</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多產品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>關於百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必讀</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意見反饋</a>&nbsp;京ICP證030173號&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
0.014::0.031::0.048::0.048::49924.000::0.000::0.031::0.000

引數				含義									時間
time_namelookup		DNS解析域名時間							0.014
time_connect		TCP連線的時間,三次握手的時間			0.031
time_starttransfer	從請求開始到第一個位元組將要傳輸的時間	0.048
time_total			總時間									0.048
speed_download		下載速度,單位-位元組每秒					49924.000
time_appconnect		SSL|SSH等上層連線建立的時間				0.000
time_pretransfer	從請求開始到響應開始傳輸的時間			0.031
time_redirect		從開始到最後一個請求事務的時間			0.000

相關文章