linuxOSの多くに標準搭載されているcurlコマンドを使ってサーバからWANまでの時間毎の応答遅延を見てみる。
/etc/cron.d設定
1/ * * * * root /tmp/networkHealth.sh >/dev/null 2>&1
networkHealth.sh
# !/bin/bash
###########################################################
## FunctionName : makeHeader
## $1 : logfilepass&filename
###########################################################
makeHeader()
{
touch $1
cat curl_header_env.config >>$1
}
###########################################################
## FunctionName : healthCheck
## $1 : logfilepass&filename
## $2 : TargetURL
###########################################################
healthCheck()
{
echo -n `date "+%H:%M:%S"`, >>$1
curl ${2} -o /dev/null -w @curl_env.config -s 2> /dev/null 1>>${1}
echo `date "+%H:%M:%S"` >>$1
}
main()
{
# init
URL=https://www.google.co.jp/
LOG_PATH=/tmp
LOG_FILE=`date "+%Y%m%d"_status.log`
# logfile check
if [ -e ${LOG_PATH}/${LOG_FILE} ]; then
echo [info] Log file already exist...skip make file.
else
echo [info] Create a log file to a new
makeHeader ${LOG_PATH}/${LOG_FILE}
fi
# healthCheck
healthCheck ${LOG_PATH}/${LOG_FILE} ${URL}
}
echo [info] `basename $0` started
main $*
echo [info] `basename $0` ended
exit 0
curl出力定義ファイル(curl_env.config)
%{url_effective},
%{http_code},
%{http_connect},
%{time_total},
%{time_namelookup},
%{time_connect},
%{time_appconnect},
%{time_pretransfer},
%{time_redirect},
%{time_starttransfer},
%{size_download},
%{size_upload},
%{size_header},
%{size_request},
%{speed_download},
%{speed_upload},
%{content_type},
%{num_connects},
%{num_redirects},
%{redirect_url},
%{ftp_entry_path},
%{ssl_verify_result},
ログファイルヘッダ定義ファイル(curl_header_env.config)
start_time,url_effective,http_code,http_connect,time_total,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer,size_download,size_upload,size_header,size_request,speed_download,speed_upload,content_type,num_connects,num_redirects,redirect_url,ftp_entry_path,ssl_verify_result.end_time
うーん、curlって相対時間は豊富にあるけど、取得開始、終了の絶対時間はないのかな。
無理矢理前後でdateで対応している。
各値の意味はman curlでオナシャス。
log
cat 20160511_status.log
start_time,url_effective,http_code,http_connect,time_total,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer,size_download,size_upload,size_header,size_request,speed_download,speed_upload,content_type,num_connects,num_redirects,redirect_url,ftp_entry_path,ssl_verify_result.end_time
00:20:01,https://www.google.co.jp/,200,000,5.233,5.047,5.061,5.157,5.157,0.000,5.232,10790,0,735,179,2062.000,0.000,text/html; charset=Shift_JIS,1,0,,,0,00:20:02
00:21:01,https://www.google.co.jp/,200,000,5.367,5.045,5.060,5.301,5.301,0.000,5.366,10694,0,735,179,1992.000,0.000,text/html; charset=Shift_JIS,1,0,,,0,00:21:03
00:22:02,https://www.google.co.jp/,200,000,5.242,5.063,5.077,5.174,5.174,0.000,5.242,10714,0,735,179,2043.000,0.000,text/html; charset=Shift_JIS,1,0,,,0,00:22:03
00:23:01,https://www.google.co.jp/,200,000,5.229,5.045,5.059,5.159,5.159,0.000,5.229,10743,0,735,179,2054.000,0.000,text/html; charset=Shift_JIS,1,0,,,0,00:23:04
00:24:01,https://www.google.co.jp/,200,000,5.233,5.048,5.064,5.165,5.165,0.000,5.233,10768,0,735,179,2057.000,0.000,text/html; charset=Shift_JIS,1,0,,,0,00:24:02