Last active
November 1, 2022 17:15
-
-
Save jim80net/e43f905380d53f660b28c5e849b3d37b to your computer and use it in GitHub Desktop.
quick and dirty ruby onliner to health check a site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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