Jump to content
aelius

Measuring website metrics with curl

Recommended Posts

Posted

I have written a short bash function for measuring website metrics such as DNS lookup, redirects, redirect time, the first byte (TTFB), connect time and the total time.

 

Short version (Only TTFB)

 

function ttfb() {
    if [ $# -eq 0 ]
        then
                echo "Usage: ttfb url"
        else
                curl -o /dev/null \
                        -H 'Cache-Control: no-cache' \
                        -s \
                        -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" \
                        $1
        fi
    }

 

Usage example:

 

aelius@macbook:~$ ttfb 
Usage: ttfb url
aelius@macbook:~$ ttfb https://www.unixteacher.org/
Connect: 0.046315 TTFB: 0.157112 Total time: 0.157400 
aelius@macbook:~$ 

 

Long version (DNS Lookup, Redirects, Redirect time, First byte, Connect time, Total time)

 

function metrics {
        if [ $# -eq 0 ]
                then
                        echo "Usage: metrics url"
                else
                        curl -H 'Cache-Control: no-cache' -Lw "DNS Lookup: %{time_namelookup} seconds \nRedirects: %{time_redirect} seconds with %{num_redirects} redirects \nFirst Byte: %{time_starttransfer} seconds \nConnect Time: %{time_connect} seconds \nTotal Time: %{time_total} seconds\n" -so /dev/null $1
                fi
        }

Usage example

 

aelius@macbook:~$ metrics 
Usage: metrics url
aelius@macbook:~$ metrics https://www.unixteacher.org/
DNS Lookup: 0.009266 seconds 
Redirects: 0.000000 seconds with 0 redirects 
First Byte: 0.173887 seconds 
Connect Time: 0.051254 seconds 
Total Time: 0.174168 seconds
aelius@macbook:~$

 

References:
– https://en.wikipedia.org/wiki/Time_to_first_byte
– https://curl.haxx.se/docs/manual.html

 

Published on UnixTeacher: https://www.unixteacher.org/blog/measuring-website-metrics-with-curl/

 

 

  • Thanks 1
  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...