Skip to content

Instantly share code, notes, and snippets.

@HarlemSquirrel
Created February 15, 2018 20:29
Show Gist options
  • Save HarlemSquirrel/b257812f5dd2ffe0bc00bc6cb54c132a to your computer and use it in GitHub Desktop.
Save HarlemSquirrel/b257812f5dd2ffe0bc00bc6cb54c132a to your computer and use it in GitHub Desktop.
Montior the status and duration of a endpoint with a GET request
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
if [ $# -eq 0 ]; then
printf "Usage:\n"
printf " $0 http://example.com [interval]\n"
exit 1
fi
URL=$1
if [[ $# -eq 2 ]]; then
INTERVAL=$2
else
INTERVAL=1
fi
printf "Checking status of $URL every $INTERVAL second(s)...\n"
printf "Date | Code | Duration\n"
for i in `seq 1 1000`;
do
date=`date`
result=`curl -X GET -s -o /dev/null -w "%{http_code} in %{time_total}s" $URL`
if [[ $result =~ ^200.* ]]; then
color=$GREEN
else
color=$RED
fi
printf "$date - Responded $color $result $NC\n"
sleep $INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment