Last Updated: January 28, 2019
·
3.968K
· errordeveloper

Measure HTTP response times with cURL and store it on Cosm

Here is a nice and simple way of measuring HTTP response of a given web site and storing the results on Cosm database. You should get some nice graphs after running this for some time as a cron job.

#!/bin/bash

MY_SITE='https://google.com'
API_KEY='<Your Cosm API key>'
FEED_ID='<Your Cosm feed ID>' 

#EXTRA_FLAGS='--verbose --location'

response_test () {

  ## See curl(1) for description of the variables
  format='dns_lookup_time,%{time_namelookup}\nconnect_time,%{time_connect}\nssl_handshake_time,%{time_appconnect}\npretransfer_time,%{time_pretransfer}\nstart_transfer_time,%{time_starttransfer}\ntotal_time,%{time_total}\nuploaded_bytes,%{size_upload}\nupload_speed,%{speed_upload}\ndownloaded_bytes,%{size_download}\ndownload_speed,%{speed_download}'
  common='--silent'

  curl $1 $common --output /dev/null $EXTRA_FLAGS --write-out $format \
   | curl $common --data-binary @- \
     -X 'PUT' \
     -H 'Host: api.cosm.com' \
     -H "X-ApiKey: $3" \
     https://api.coms.com/v2/feeds/$2.csv
}

response_test $MY_SITE $FEED_ID $API_KEY

Of coure, you can improve this to actually send some payload to your site and not google.com!