Last active
November 25, 2017 17:27
-
-
Save sandeepraju/5a577d41d5d43b631183ed33bdafaa8a to your computer and use it in GitHub Desktop.
A simple script to log the TTFB (Time to First Byte) of a given web link
This file contains 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
#!/bin/bash | |
# file: monitor-ttfb.sh | |
# note: to deploy this, add the following line to your crontab | |
# * 10-17 * * 1-5 /path/to/monitor-ttfb.sh "https://domain-to-monitor.com" /path/to/log-file.log | |
# the above cronjob runs every minute from 10AM to 5PM only on weekdays | |
function ttfb() { | |
curl -o /dev/null \ | |
-H 'Cache-Control: no-cache' \ | |
-H 'Accept-Encoding: gzip, deflate, sdch' \ | |
-H 'Accept-Language: en-US,en;q=0.8' \ | |
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' \ | |
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \ | |
--compressed \ | |
-s \ | |
-w "%{time_connect} %{time_starttransfer} %{time_total}" \ | |
$1 | |
} | |
function clean_url() { | |
echo $1 | sed 's~http[s]*://~~g' | sed 's~/$~~g' | |
} | |
function clean_trailing_slash() { | |
echo $1 | sed 's~/$~~g' | |
} | |
echo $(date "+%Y-%m-%d %H:%M:%S") $1 $(ttfb $1) | tr '\n' ' ' | sed 's/$//g' >> $(clean_trailing_slash $2)/$(date "+%Y-%m-%d")-$(clean_url $1).log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment