在電腦-使用curl檢測url狀況及時間中使用curl相關指令,對url進行一次性測試。
如果要長時間測試可以用script搭配cron排程進行。
script也將應用awk,curl中的相關時間進行計算如:
1.TCP連接時間(TCP Connection):%{time_pretransfer}-%{time_namelookup}
2.Server 處理時間(Content Generation、Processing Time):%{time_starttransfer}-%{time_pretransfer}
3.內容傳輸時間(Content Transfer):%{time_total}-%{time_starttransfer}
指定curl輸出格式
CURL_F='%{http_code},%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total}'
curl指令
curl -w "$CURL_F" -o /dev/null -sS "$@"
#$@ 可代入的相關參數,如https://www.google.com.tw
指定awk輸出格式
AWK_F='$0"\nServer_Processing:"$7-$6"\nContent_Transfer:"$8-$7'
awk指令
awk 'BEGIN {FS=","}; {print '$DATE'",\n"'$AWK_F'}'
完整指令
==
DATE=`date +'%Y%m%d%H%M'`
CURL_F='%{http_code},%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total}
AWK_F='$0","$7-$6","$8-$7'
curl -w "$CURL_F" -o /dev/null -sS "$@"| awk 'BEGIN {FS=","}; {print '$DATE'","'$AWK_F'}'
==
執行指令
./curltest.sh https://www.google.com.tw
輸出結果
201905171513,200,0.004,0.007,0.102,0.102,0.000,0.134,0.135,0.134,0.00
欄位分別對應:
時間,%{http_code},%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total},Server Processing,Content Transfer
參考資料:
https://github.com/mat/dotfiles/blob/master/bin/curlt
Measuring HTTP response times with cURL
What Do Curl Timings Mean?
HTTP Request Timings with cURL
HTTP Transaction Timing Breakdown with cURL
Performance Testing with cURL, Part 1: Basics
Performance Testing with cURL, Part 2: Scripting
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。