Use curl to measure site metrics

0
3031
Use curl to measure site metrics
Use curl to measure site metrics

curl is a great utility to make network requests and transfer data across the Internet, but do you know that we can also use curl to measure site metrics? I will show you a curl trick on this post.

According to the curl manual, these metrics are available to measure:

  • time_appconnect: The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.
  • time_connect: The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
  • time_namelookup: The time, in seconds, it took from the start until the name resolving was completed.
  • time_pretransfer: The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
  • time_redirect: The time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections.
  • time_starttransfer: The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
  • time_total: The total time, in seconds, that the full operation lasted.

So, how do we use it?

You can run this command:

$ curl -L --output /dev/null --silent --show-error --write-out 'lookup: %{time_namelookup}\nconnect: %{time_connect}\nappconnect: %{time_appconnect}\npretransfer: %{time_pretransfer}\nredirect: %{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal: %{time_total}\n' 'WEBSITE_URL'

Make sure to replace WEBSITE_URL to appropriate website URLs.

For example, to measure my blog, I’d issue following command:

$ curl -L --output /dev/null --silent --show-error --write-out 'lookup: %{time_namelookup}\nconnect: %{time_connect}\nappconnect: %{time_appconnect}\npretransfer: %{time_pretransfer}\nredirect: %{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal: %{time_total}\n' 'https://blog.petehouston.com'

lookup: 0.009328
connect: 0.081027
appconnect: 0.148230
pretransfer: 0.148292
redirect: 0.000000
starttransfer: 0.403199
total: 0.620312

You might notice that my result has redirect: 0 sec, right? It is because there is no redirection taken when accessing the https scheme. However, if the request is made to http scheme, it should take some times to redirect from http to https.

$ curl -L --output /dev/null --silent --show-error --write-out 'lookup: %{time_namelookup}\nconnect: %{time_connect}\nappconnect: %{time_appconnect}\npretransfer: %{time_pretransfer}\nredirect: %{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal: %{time_total}\n' 'http://blog.petehouston.com'

lookup: 0.010393
connect: 0.144574
appconnect: 0.150150
pretransfer: 0.230135
redirect: 0.160902
starttransfer: 0.609766
total: 0.869292

Alright, that’s how you use curl to measure site metrics.

Good luck!