Skip to content

Instantly share code, notes, and snippets.

@jim80net
Last active November 1, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jim80net/e43f905380d53f660b28c5e849b3d37b to your computer and use it in GitHub Desktop.
Save jim80net/e43f905380d53f660b28c5e849b3d37b to your computer and use it in GitHub Desktop.
quick and dirty ruby onliner to health check a site
ruby -rcolorize -rnet/http -e '
def check()
s_time = Time.now()
res = Net::HTTP.get_response(URI( "https://example.com/"))
ensure
e_time = Time.now()
code = defined?(res.code) ? res.code : "5xx"
return [e_time - s_time, code]
end
while true do
sleep 1
result = check()
time = result[0].round(2)
code = result[1]
if code == "200"
time_s = "#{time},"
if time > 0.9
printf time_s.red
elsif time > 0.3
printf time_s.yellow
else
printf time_s
end
else
printf "#{time}!".red.bold
end
end'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment