Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Last active July 6, 2023 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mttjohnson/a93c6a3c3b11778873c24b5dfac793b8 to your computer and use it in GitHub Desktop.
Save mttjohnson/a93c6a3c3b11778873c24b5dfac793b8 to your computer and use it in GitHub Desktop.
Web (Curl) Request Performance Timing (with HTTPS DNS resolver caching to alternate hosts)
# Some output format parameters require newer versions of curl
# These examples were done with Curl 7.54.0 with HTTP/2 Support
# The kind of output you would expect to see with the two functions here (time_url and url_ping) would look like this:
[user@683dd22606f5 /]# URL_TO_CHECK="https://venia.magento.com/graphql?query=query+getProductDetailForProductPage..."
[user@683dd22606f5 /]# time_url "${URL_TO_CHECK}"
url_effective: https://venia.magento.com/graphql?query=query+getProductDetailForProductPage...
remote_ip: 151.101.129.124
http_code: 200
http_version: 2
web_server:
varnish_cache:
varnish_age: 3967
----------
time_namelookup: 0.091770
time_connect: 0.140731
time_appconnect: 0.355792
time_pretransfer: 0.356469
time_redirect: 0.000000
time_starttransfer: 0.406902 (TTFB - Time To First Byte)
----------
time_total: 0.488123
------------------------------
DNS Lookup: 0.091770
TCP Handshake: 0.048961 (RTT - Round Trip Time)
SSL Handshake: 0.215061
Wait: 0.050433
Server Processing: 0.001472
Data Transfer: 0.081221
Speed Download: 1.48Mbps
Size Download: 92KB
[user@683dd22606f5 /]# url_ping "${URL_TO_CHECK}"
CUR_TIME: TAG - URL_EFFECTIVE (REMOTE_IP) - HTTP_CODE HTTP HTTP_VERSION - SERVER_PROCESSING_TIMEms of TIME_TOTALms [DIFF_TIMEms] (VARNISH_CACHE_STATUS VARNISH_CACHE_AGE)
2022-09-04 17:01:00: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - 431ms of 827ms [396ms] (MISS,MISS 0)
2022-09-04 17:01:06: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - 25ms of 392ms [367ms] (MISS,HIT 6)
2022-09-04 17:01:11: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 9ms of 380ms [371ms] (MISS,HIT 11)
2022-09-04 17:01:17: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 15ms of 406ms [391ms] (MISS,HIT 17)
2022-09-04 17:01:22: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 12ms of 412ms [400ms] (MISS,HIT 22)
2022-09-04 17:01:28: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 14ms of 427ms [413ms] (MISS,HIT 28)
2022-09-04 17:01:33: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 6ms of 367ms [361ms] (MISS,HIT 33)
2022-09-04 17:01:39: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 19ms of 421ms [402ms] (MISS,HIT 39)
2022-09-04 17:01:45: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 17ms of 417ms [400ms] (MISS,HIT 44)
2022-09-04 17:01:50: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 15ms of 429ms [414ms] (MISS,HIT 50)
2022-09-04 17:01:56: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 7ms of 335ms [328ms] (MISS,HIT 55)
2022-09-04 17:02:01: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - -5ms of 447ms [452ms] (MISS,HIT 61)
2022-09-04 17:02:07: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - 5ms of 342ms [337ms] (MISS,HIT 66)
2022-09-04 17:02:12: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - 7ms of 375ms [368ms] (MISS,HIT 72)
2022-09-04 17:02:18: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - 7ms of 486ms [479ms] (MISS,HIT 77)
2022-09-04 17:02:23: - venia.magento.com/graphql (151.101.1.124) - 200 HTTP 2 - 15ms of 407ms [392ms] (MISS,HIT 83)
2022-09-04 17:02:29: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 5ms of 400ms [395ms] (MISS,HIT 88)
2022-09-04 17:02:34: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 14ms of 369ms [355ms] (MISS,HIT 94)
2022-09-04 17:02:40: - venia.magento.com/graphql (151.101.193.124) - 200 HTTP 2 - 4ms of 383ms [379ms] (MISS,HIT 99)
2022-09-04 17:06:30: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 483ms of 927ms [444ms] (MISS,MISS 0)
2022-09-04 17:06:36: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 427ms of 818ms [391ms] (MISS,MISS 0)
2022-09-04 17:06:42: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 583ms of 932ms [349ms] (MISS,MISS 0)
2022-09-04 17:06:48: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 467ms of 871ms [404ms] (MISS,MISS 0)
2022-09-04 17:06:54: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 611ms of 982ms [371ms] (MISS,MISS 0)
2022-09-04 17:30:47: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 6ms of 359ms [353ms] (MISS,HIT 1789)
2022-09-04 17:30:53: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 10ms of 394ms [384ms] (MISS,HIT 1794)
2022-09-04 17:30:58: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 6ms of 557ms [551ms] (MISS,HIT 1800)
2022-09-04 17:31:04: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 1ms of 375ms [374ms] (MISS,HIT 1806)
2022-09-04 17:31:09: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 81ms of 486ms [405ms] (MISS,HIT 1811)
2022-09-04 17:31:15: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 1ms of 348ms [347ms] (MISS,HIT 1817)
2022-09-04 17:31:21: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 16ms of 389ms [373ms] (MISS,HIT 1822)
2022-09-04 17:33:29: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 290ms of 730ms [440ms] (MISS,HIT 1950)
2022-09-04 17:33:34: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 5ms of 617ms [612ms] (MISS,HIT 1957)
2022-09-04 17:33:40: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 12ms of 416ms [404ms] (MISS,HIT 1962)
2022-09-04 17:33:46: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 12ms of 405ms [393ms] (MISS,HIT 1967)
2022-09-04 17:33:51: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 0ms of 439ms [439ms] (MISS,HIT 1973)
2022-09-04 17:33:57: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 11ms of 364ms [353ms] (MISS,HIT 1978)
2022-09-04 17:34:02: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 16ms of 431ms [415ms] (MISS,HIT 1984)
2022-09-04 17:34:08: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 8ms of 512ms [504ms] (MISS,HIT 1989)
2022-09-04 17:34:13: - venia.magento.com/graphql (151.101.129.124) - 200 HTTP 2 - 1ms of 465ms [464ms] (MISS,HIT 1995)
2022-09-05 20:23:54: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 406ms of 1169ms [763ms] (MISS,MISS 0)
2022-09-05 20:24:00: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 38ms of 624ms [586ms] (MISS,HIT 6)
2022-09-05 20:24:06: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 6ms of 796ms [790ms] (MISS,HIT 12)
2022-09-05 20:24:12: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 37ms of 664ms [627ms] (MISS,HIT 17)
2022-09-05 20:24:18: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 2ms of 365ms [363ms] (MISS,HIT 23)
2022-09-05 20:24:23: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 11ms of 926ms [915ms] (MISS,HIT 29)
2022-09-05 20:24:29: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 4ms of 1102ms [1098ms] (MISS,HIT 35)
2022-09-05 20:24:35: - venia.magento.com/graphql (151.101.65.124) - 200 HTTP 2 - 5ms of 416ms [411ms] (MISS,HIT 41)
# Alternate timing utility
python --version
pip install httpstat
yum install python36u python36u-pip
python3.6 --version
pip3.6 --version
pip3.6 install httpstat
httpstat https://github.com/
# Curl Timing Reference: https://blog.cloudflare.com/a-question-of-timing/
# Possible Dependencies:
#yum -y install perl-CPAN
#yum -y install perl-HTTP-Tiny
#perl -MCPAN -e 'install Math::FixedPoint'
# Get timing details for a request goping to a specific IP
URL_DOMAIN="www.example.com"
URL_TO_CHECK="https://${URL_DOMAIN}/"
time_url "${URL_TO_CHECK}" "--resolve ${URL_DOMAIN}:443:127.0.0.1" # Loacalhost
time_url "${URL_TO_CHECK}" "--resolve ${URL_DOMAIN}:443:1.2.3.4" # Example Server 1
function time_url {
CURL_URL="$1"
CURL_RESOLVE="$2"
CURL_HTTP_VER_SUP=false # curl version > 7.50.0 supports %{http_version}
CURL_HTTP_VER=""
CURL_VER_MAIN=$(curl --version | grep -i '^curl ' | cut -d ' ' -f 2 | tr -d '[:space:]' | cut -d '.' -f 1)
CURL_VER_REL=$(curl --version | grep -i '^curl ' | cut -d ' ' -f 2 | tr -d '[:space:]' | cut -d '.' -f 2)
if [[ ${CURL_VER_MAIN} =~ ^[0-9]+$ ]] && [ ${CURL_VER_MAIN} -ge 7 ] && [[ ${CURL_VER_REL} =~ ^[0-9]+$ ]] && [ ${CURL_VER_REL} -ge 50 ]; then
CURL_HTTP_VER_SUP=true
CURL_HTTP_VER="http_version| %{http_version}"
fi
CURL_FORMAT=$(echo "
time_namelookup: %{time_namelookup}
time_connect: %{time_connect}
time_appconnect: %{time_appconnect}
time_pretransfer: %{time_pretransfer}
time_redirect: %{time_redirect}
time_starttransfer: %{time_starttransfer}
size_download: %{size_download}
speed_download: %{speed_download}
----------
time_total: %{time_total}
url_effective| %{url_effective}
remote_ip| %{remote_ip}
http_code| %{http_code}
${CURL_HTTP_VER}
\n")
CURL_RESPONSE=$(curl -w "${CURL_FORMAT}" -o /dev/null -D - -sk -H "X-Debug: 1" "${CURL_URL}" ${CURL_RESOLVE})
TIME_NAMELOOKUP=$(echo "${CURL_RESPONSE}" | grep 'time_namelookup' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_CONNECT=$(echo "${CURL_RESPONSE}" | grep 'time_connect' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_APPCONNECT=$(echo "${CURL_RESPONSE}" | grep 'time_appconnect' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_PRETRANSFER=$(echo "${CURL_RESPONSE}" | grep 'time_pretransfer' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_REDIRECT=$(echo "${CURL_RESPONSE}" | grep 'time_redirect' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_STARTTRANSFER=$(echo "${CURL_RESPONSE}" | grep 'time_starttransfer' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_TOTAL=$(echo "${CURL_RESPONSE}" | grep 'time_total' | cut -d ':' -f 2 | tr -d '[:space:]')
SIZE_DOWNLOAD=$(echo "${CURL_RESPONSE}" | grep -i 'size_download' | cut -d ':' -f 2 | tr -d '[:space:]')
SPEED_DOWNLOAD=$(echo "${CURL_RESPONSE}" | grep -i 'speed_download' | cut -d ':' -f 2 | tr -d '[:space:]')
URL_EFFECTIVE=$(echo "${CURL_RESPONSE}" | grep -i 'url_effective' | cut -d '|' -f 2 | tr -d '[:space:]')
REMOTE_IP=$(echo "${CURL_RESPONSE}" | grep -i 'remote_ip' | cut -d '|' -f 2 | tr -d '[:space:]')
HTTP_CODE=$(echo "${CURL_RESPONSE}" | grep -i 'http_code' | cut -d '|' -f 2 | tr -d '[:space:]')
HTTP_VERSION=$(echo "${CURL_RESPONSE}" | grep -i 'http_version' | cut -d '|' -f 2 | tr -d '[:space:]')
VARNISH_CACHE_AGE=$(echo "${CURL_RESPONSE}" | grep -i 'age:' | cut -d ':' -f 2 | tr -d '[:space:]')
VARNISH_CACHE_STATUS=$(echo "${CURL_RESPONSE}" | grep -i 'x-magento-cache-debug' | cut -d ':' -f 2 | tr -d '[:space:]')
HEADER_SERVER=$(echo "${CURL_RESPONSE}" | grep -i 'x-server' | cut -d ':' -f 2 | tr -d '[:space:]')
TCP_HANDSHAKE_TIME=$(perl -E "say (${TIME_CONNECT} - ${TIME_NAMELOOKUP})")
SSL_HANDSHAKE_TIME=$(perl -E "say (${TIME_APPCONNECT} - ${TIME_CONNECT})")
WAIT_TIME=$(perl -E "say (${TIME_STARTTRANSFER} - ${TIME_PRETRANSFER})")
SERVER_PROCESSING_TIME=$(perl -E "printf('%.6f', (((${TIME_STARTTRANSFER} - ${TIME_PRETRANSFER}) - (${TIME_CONNECT} - ${TIME_NAMELOOKUP})) ) )")
#SERVER_PROCESSING_TIME=$(perl -e "use Math::FixedPoint; print ((Math::FixedPoint->new('${TIME_STARTTRANSFER}') - Math::FixedPoint->new('${TIME_PRETRANSFER}')) - (Math::FixedPoint->new('${TIME_CONNECT}') - Math::FixedPoint->new('${TIME_NAMELOOKUP}')));")
SPEED_DOWNLOAD=$(perl -E "printf('%.2f', (${SPEED_DOWNLOAD} * 8 / 1024 / 1024) )")
SIZE_DOWNLOAD=$(perl -E "printf('%.0f', (${SIZE_DOWNLOAD} / 1024) )")
DATA_TRANSFER_TIME=$(perl -E "printf('%.6f', (((${TIME_TOTAL} - ${TIME_STARTTRANSFER}) ) ) )")
#DATA_TRANSFER_TIME=$(perl -e "use Math::FixedPoint; print ( (Math::FixedPoint->new('${TIME_TOTAL}') - Math::FixedPoint->new('${TIME_STARTTRANSFER}')) );")
echo "
url_effective: ${URL_EFFECTIVE}
remote_ip: ${REMOTE_IP}
http_code: ${HTTP_CODE}
http_version: ${HTTP_VERSION}
web_server: ${HEADER_SERVER}
varnish_cache: ${VARNISH_CACHE_STATUS}
varnish_age: ${VARNISH_CACHE_AGE}
----------
time_namelookup: ${TIME_NAMELOOKUP}
time_connect: ${TIME_CONNECT}
time_appconnect: ${TIME_APPCONNECT}
time_pretransfer: ${TIME_PRETRANSFER}
time_redirect: ${TIME_REDIRECT}
time_starttransfer: ${TIME_STARTTRANSFER} (TTFB - Time To First Byte)
----------
time_total: ${TIME_TOTAL}
------------------------------
DNS Lookup: ${TIME_NAMELOOKUP}
TCP Handshake: ${TCP_HANDSHAKE_TIME} (RTT - Round Trip Time)
SSL Handshake: ${SSL_HANDSHAKE_TIME}
Wait: ${WAIT_TIME}
Server Processing: ${SERVER_PROCESSING_TIME}
Data Transfer: ${DATA_TRANSFER_TIME}
Speed Download: ${SPEED_DOWNLOAD}Mbps
Size Download: ${SIZE_DOWNLOAD}KB
"
}
#yum -y install perl-CPAN
#yum -y install perl-HTTP-Tiny
#yum -y install perl-IO-Socket-SSL
#perl -MCPAN -e 'install Math::FixedPoint'
#perl -MCPAN -e 'install "URI"'
# Optionally override some default settings
USE_RAND_QS="true"
SLEEP_TIME="0.1"
url_ping "${URL_TO_CHECK}" "${URL_DOMAIN}:443:1.2.3.4" # Example Server 1
# Ping style ouput of request (with server processing time)
function url_ping {
CURL_URL="$1"
CURL_RESOLVE="$2"
USE_RAND_QS=${USE_RAND_QS:-"false"} # Set default if not already defined
SLEEP_TIME=${SLEEP_TIME:-"5"} # Set default if not already defined
TAG=""
RED='\033[0;31m' # Red Text
GREEN='\033[0;32m' # Green Text
PURPLE='\033[0;35m' # Purple Text
NC='\033[0m' # No Color
CURL_OPTS=()
[[ ! -z "${CURL_RESOLVE}" ]] && CURL_OPTS+=("--resolve" "${CURL_RESOLVE}")
CURL_HTTP_VER_SUP=false # curl version > 7.50.0 supports %{http_version}
CURL_HTTP_VER=""
CURL_VER_MAIN=$(curl --version | grep -i '^curl ' | cut -d ' ' -f 2 | tr -d '[:space:]' | cut -d '.' -f 1)
CURL_VER_REL=$(curl --version | grep -i '^curl ' | cut -d ' ' -f 2 | tr -d '[:space:]' | cut -d '.' -f 2)
if [[ ${CURL_VER_MAIN} =~ ^[0-9]+$ ]] && [ ${CURL_VER_MAIN} -ge 7 ] && [[ ${CURL_VER_REL} =~ ^[0-9]+$ ]] && [ ${CURL_VER_REL} -ge 50 ]; then
CURL_HTTP_VER_SUP=true
CURL_HTTP_VER="http_version| %{http_version}"
fi
CURL_FORMAT=$(echo "
time_namelookup: %{time_namelookup}
time_connect: %{time_connect}
time_pretransfer: %{time_pretransfer}
time_starttransfer: %{time_starttransfer}
----------
time_total: %{time_total}
url_effective| %{url_effective}
remote_ip| %{remote_ip}
http_code| %{http_code}
${CURL_HTTP_VER}
\n")
echo "CUR_TIME: TAG - URL_EFFECTIVE (REMOTE_IP) - HTTP_CODE HTTP HTTP_VERSION - SERVER_PROCESSING_TIMEms of TIME_TOTALms [DIFF_TIMEms] (VARNISH_CACHE_STATUS VARNISH_CACHE_AGE)"
while true; do
if [ "${USE_RAND_QS}" = true ]; then CURL_URL_RAND_QS="?t=$(date '+%Y%m%d%H%M%S')$((1 + RANDOM % 1000))"
else CURL_URL_RAND_QS=""
fi
CUR_TIME=$(date '+%Y-%m-%d %H:%M:%S')
CURL_RESPONSE=$(curl "${CURL_OPTS[@]}" -H 'X-Debug: 1' -D - -w "${CURL_FORMAT}" -o /dev/null -s "${CURL_URL}${CURL_URL_RAND_QS}")
TIME_NAMELOOKUP=$(echo "${CURL_RESPONSE}" | grep -i 'time_namelookup' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_CONNECT=$(echo "${CURL_RESPONSE}" | grep -i 'time_connect' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_PRETRANSFER=$(echo "${CURL_RESPONSE}" | grep -i 'time_pretransfer' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_STARTTRANSFER=$(echo "${CURL_RESPONSE}" | grep -i 'time_starttransfer' | cut -d ':' -f 2 | tr -d '[:space:]')
TIME_TOTAL=$(echo "${CURL_RESPONSE}" | grep -i 'time_total' | cut -d ':' -f 2 | tr -d '[:space:]')
URL_EFFECTIVE=$(echo "${CURL_RESPONSE}" | grep -i 'url_effective' | cut -d '|' -f 2 | tr -d '[:space:]')
REMOTE_IP=$(echo "${CURL_RESPONSE}" | grep -i 'remote_ip' | cut -d '|' -f 2 | tr -d '[:space:]')
HTTP_CODE=$(echo "${CURL_RESPONSE}" | grep -i 'http_code' | cut -d '|' -f 2 | tr -d '[:space:]')
HTTP_VERSION=$(echo "${CURL_RESPONSE}" | grep -i 'http_version' | cut -d '|' -f 2 | tr -d '[:space:]')
X_SERVER=$(echo "${CURL_RESPONSE}" | grep -i 'x-server:' | head -1 | cut -d ':' -f 2 | tr -d '[:space:]')
VARNISH_CACHE_AGE=$(echo "${CURL_RESPONSE}" | grep -i 'age:' | cut -d ':' -f 2 | tr -d '[:space:]')
VARNISH_CACHE_STATUS=$(echo "${CURL_RESPONSE}" | grep -i 'x-magento-cache-debug' | cut -d ':' -f 2 | tr -d '[:space:]')
[[ -z "${VARNISH_CACHE_STATUS}" ]] && VARNISH_CACHE_STATUS=$(echo "${CURL_RESPONSE}" | grep -i 'x-cache:' | cut -d ':' -f 2 | tr -d '[:space:]')
[[ "${VARNISH_CACHE_STATUS}" == "MISS" ]] && VARNISH_CACHE_STATUS="${RED}${VARNISH_CACHE_STATUS}${NC}"
SERVER_PROCESSING_TIME=$(perl -E "printf('%.0f', (((${TIME_STARTTRANSFER} - ${TIME_PRETRANSFER}) - (${TIME_CONNECT} - ${TIME_NAMELOOKUP})) * 1000) )")
#SERVER_PROCESSING_TIME=$(perl -e "use Math::FixedPoint; print (Math::FixedPoint->new((((Math::FixedPoint->new('${TIME_STARTTRANSFER}') - Math::FixedPoint->new('${TIME_PRETRANSFER}')) - (Math::FixedPoint->new('${TIME_CONNECT}') - Math::FixedPoint->new('${TIME_NAMELOOKUP}'))) * Math::FixedPoint->new('1000')), 0));")
TIME_TOTAL=$(perl -E "printf('%.0f', (${TIME_TOTAL} * 1000) )")
DIFF_TIME=$(perl -E "printf('%.0f', (${TIME_TOTAL} - ${SERVER_PROCESSING_TIME}) )")
DATA_TRANSFER_TIME=$(perl -E "say (${TIME_TOTAL} - ${TIME_STARTTRANSFER})")
HTTP_CODE_DISPLAY="${HTTP_CODE}"
[[ "${HTTP_CODE}" == "200" ]] && HTTP_CODE_DISPLAY="${GREEN}${HTTP_CODE}${NC}"
[[ "${HTTP_CODE}" == "500" ]] && HTTP_CODE_DISPLAY="${RED}${HTTP_CODE}${NC}"
[[ "${HTTP_CODE}" == "502" ]] && HTTP_CODE_DISPLAY="${RED}${HTTP_CODE}${NC}"
[[ "${HTTP_CODE}" == "404" ]] && HTTP_CODE_DISPLAY="${PURPLE}${HTTP_CODE}${NC}"
URL_DISPLAY=$(echo "${URL_EFFECTIVE}" | perl -MURI -wlne '$uri = URI->new($_); print $uri->host, $uri->path, "\n";')
echo -e "${CUR_TIME}: ${TAG} - ${URL_DISPLAY:0:40} (${REMOTE_IP}) - ${HTTP_CODE_DISPLAY} HTTP ${HTTP_VERSION} - ${SERVER_PROCESSING_TIME}ms of ${TIME_TOTAL}ms [${DIFF_TIME}ms] (${VARNISH_CACHE_STATUS} ${VARNISH_CACHE_AGE}) ${X_SERVER}"
sleep $SLEEP_TIME
done
}
# Ping style ouput of request
CURL_FORMAT=$(echo "%{url_effective} (%{remote_ip}) - %{http_code} HTTP %{http_version} - %{time_total}\n")
CURL_OPTS=()
CURL_URL="https://github.com/" USE_RAND_QS=false
TAG="MyTagName" CURL_RESOLVE="www.github.com:443:192.30.253.113" # Example GitHub IP
while true; do
if [ "${USE_RAND_QS}" = true ]; then CURL_URL_RAND_QS="?t=$(date '+%Y%m%d%H%M%S')$((1 + RANDOM % 1000))"
else CURL_URL_RAND_QS=""
fi
CUR_TIME=$(date '+%Y-%m-%d %H:%M:%S')
printf "${CUR_TIME}: ${TAG} - "
curl "${CURL_OPTS[@]}" -w "${CURL_FORMAT}" -o /dev/null -s "${CURL_URL}${CURL_URL_RAND_QS}" --resolve "${CURL_RESOLVE}"
sleep 5
done
# Example Output:
# 2018-04-16 13:08:38: MyTagName - https://github.com/ (192.30.253.113) - 200 HTTP 1.1 - 0.345567
# 2018-04-16 13:08:43: MyTagName - https://github.com/ (192.30.253.113) - 200 HTTP 1.1 - 0.243592
# 2018-04-16 13:08:49: MyTagName - https://github.com/ (192.30.253.112) - 200 HTTP 1.1 - 0.259549
# 2018-04-16 13:08:54: MyTagName - https://github.com/ (192.30.253.112) - 200 HTTP 1.1 - 0.240476
# Adding a random query string to the URL
CURL_URL="https://github.com/" USE_RAND_QS=true
# Example Output:
# 2018-04-16 13:11:45: MyTagName - https://github.com/?t=2018041613114556 (192.30.253.112) - 200 HTTP 1.1 - 0.276090
# 2018-04-16 13:11:51: MyTagName - https://github.com/?t=20180416131151776 (192.30.253.112) - 200 HTTP 1.1 - 0.254329
# 2018-04-16 13:11:56: MyTagName - https://github.com/?t=20180416131156842 (192.30.253.113) - 200 HTTP 1.1 - 0.276037
# 2018-04-16 13:12:01: MyTagName - https://github.com/?t=20180416131201568 (192.30.253.113) - 200 HTTP 1.1 - 0.276019
# Running requests locally on the web servers
# For Local requests with newer curl versions (curl 7.29.0 - CentOS 7.4)
CURL_FORMAT=$(echo "%{url_effective} (%{remote_ip}) - %{http_code} - %{time_total}\n")
CURL_URL="https://www.example.com/"
TAG="MyTagName" CURL_RESOLVE="www.example.com:443:127.0.0.1" # Localhost
while true; do
CUR_TIME=$(date '+%Y-%m-%d %H:%M:%S')
printf "${CUR_TIME}: ${TAG} - "
curl -w "${CURL_FORMAT}" -o /dev/null -s "${CURL_URL}" --resolve "${CURL_RESOLVE}"
sleep 5
done
# For Local requests with older curl versions (curl 7.19.7 - CentOS 6.9)
# Send the request to the local IP using Host headers for the domain requested ignoring SSL Validation
CURL_FORMAT=$(echo "%{url_effective} - %{http_code} - %{time_total}\n")
CURL_URL="https://127.0.0.1/"
CURL_HOST="www.example.com"
while true; do
CUR_TIME=$(date '+%Y-%m-%d %H:%M:%S')
printf "${CUR_TIME}: - "
curl -w "${CURL_FORMAT}" -o /dev/null -sk -H "Host: ${CURL_HOST}" "${CURL_URL}"
sleep 5
done
# Send request to backend nginx instance bypassing SSL and nginx reverse proxy
CURL_FORMAT=$(echo "%{url_effective} - %{http_code} - %{time_total}\n")
CURL_URL="http://127.0.0.1:8080/"
CURL_HOST="www.example.com"
while true; do
CUR_TIME=$(date '+%Y-%m-%d %H:%M:%S')
printf "${CUR_TIME}: - "
curl -s \
-w "${CURL_FORMAT}" -o /dev/null \
-H "Host: ${CURL_HOST}" \
-H "X-Forwarded-Proto: https" \
"${CURL_URL}"
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment