Last active
October 10, 2023 07:08
-
-
Save t2psyto/1c6ba7378596591a57e204983259ee09 to your computer and use it in GitHub Desktop.
curl でwebの応答時間をログ出力する for windows環境
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
echo ■■ パタン1: インターネット(yahoo) | |
set cwd1=%~dp0 | |
set cwd=%cwd1:~0,-1% | |
rem タイムスタンプ YYYYMMDD_hhmmss を取得 | |
set time2=%time: =0% | |
set time3=%time2::=% | |
set timestamp=%date:/=%_%time3:~0,6% | |
rem echo timestamp: %timestamp% | |
rem 接続先ログファイルのパス | |
set LOGDIR=%cwd%\web応答計測 | |
rem set LOGFILE=%cwd%\%timestamp%_%COMPUTERNAME%_webresponse.log | |
mkdir %LOGDIR% > nul 2>&1 | |
set LOGFILE=%LOGDIR%\%timestamp%_%COMPUTERNAME%_web応答テスト_Yahoo.log | |
rem 接続先URL | |
set URL=http://yahoo.co.jp | |
rem PROXY | |
set HTTP_PROXY= | |
set HTTPS_PROXY= | |
rem 試行回数 | |
set CYCLE=3 | |
echo ■ webサーバの応答速度を計測します。 | |
echo timestamp: %timestamp% | |
echo URL: %URL% | |
echo HTTP_PROXY: %HTTP_PROXY% | |
echo LOGFILE: %LOGFILE% | |
echo. | |
set CURL_RESULT_HEADER=timestamp, content_type, filename_effective, ftp_entry_path, http_code, http_connect, local_ip, local_port, num_connects, num_redirects, redirect_url, remote_ip, remote_port, size_download, size_header, size_request, size_upload, speed_download, speed_upload, ssl_verify_result, time_appconnect, time_connect, time_namelookup, time_pretransfer, time_redirect, time_starttransfer, time_total, url_effective | |
echo %CURL_RESULT_HEADER% >> %LOGFILE% | |
for /l %%i in (1, 1, %CYCLE%) do ( | |
echo □ 回数: %%i / %CYCLE% | |
rem @echo|set /p=%timestamp% >> %LOGFILE% | |
del /S /Q %TEMP%\tmpclip*.txt > nul 2>&1 | |
curl -m 3 %URL% -o NUL -SsfL -w "%%{content_type}, %%{filename_effective}, %%{ftp_entry_path}, %%{http_code}, %%{http_connect}, %%{local_ip}, %%{local_port}, %%{num_connects}, %%{num_redirects}, %%{redirect_url}, %%{remote_ip}, %%{remote_port}, %%{size_download}, %%{size_header}, %%{size_request}, %%{size_upload}, %%{speed_download}, %%{speed_upload}, %%{ssl_verify_result}, %%{time_appconnect}, %%{time_connect}, %%{time_namelookup}, %%{time_pretransfer}, %%{time_redirect}, %%{time_starttransfer}, %%{time_total}, %%{url_effective}" 2> %TEMP%\tmpcliperr.txt 1> %TEMP%\tmpclip.txt | |
rem curl のエラーメッセージを計測結果に結合 | |
if exist %TEMP%\tmpcliperr.txt ( | |
echo|set /p=, >> %TEMP%\tmpclip.txt | |
type %TEMP%\tmpcliperr.txt >> %TEMP%\tmpclip.txt | |
) | |
rem curl 計測結果を環境変数に格納 | |
for /f "usebackq delims=\\" %%i in (`type %TEMP%\tmpclip.txt`) do set CURL_RESULT=%timestamp%, %%i | |
del /S /Q %TEMP%\tmpclip*.txt > nul 2>&1 | |
echo %CURL_RESULT_HEADER% | |
echo !CURL_RESULT! | |
echo !CURL_RESULT! >> %LOGFILE% | |
echo. | |
timeout /T 5 > nul | |
) | |
echo. | |
echo. | |
echo ■ 計測が完了しました。 | |
echo. | |
echo. | |
echo. | |
echo. | |
rem pause | |
echo ■ 計測がすべて完了しました。終了します。 | |
timeout /T 5 /NOBREAK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
接続エラーの時はログ末尾にcurlのエラーメッセージがつく。
下記はプロキシに接続できなかった場合のログ