webserver status, need better approach

W

Walle Wallen

Hey, I need a better way of checking if a webserver is online and
operational. The following code
works ok, but it sometimes returns the wrong result. Does anyone have a
better approach?

//Walle

def check_http(server)
Timeout::timeout(10.0) do
if(Net::HTTP.get_response(URI.parse("http://#{server}.something.com")).code
== "200")
return true
end
return false
end
rescue Timeout::Error
return false
rescue
return false
end
 
H

Hassan Schroeder

Hey, I need a better way of checking if a webserver =A0is online and
operational. The following code works ok, but it sometimes returns the wr=
ong result.

Under what circumstances does it fail?
def check_http(server)
=A0Timeout::timeout(10.0) do
=A0 =A0if(Net::HTTP.get_response(URI.parse("http://#{server}.something.co= m")).code =3D=3D "200")
=A0 =A0return true
=A0 =A0end
=A0 =A0return false
=A0end
=A0rescue Timeout::Error
=A0return false
=A0rescue
=A0return false
=A0end

In any case, that seems rather convoluted; I cut it down to this:

def check_http(server)
Net::HTTP.get_response(URI.parse("http://#{server}")).code =3D=3D "200"
end

:: and it seemed to work just fine. :)

FWIW,
--=20
Hassan Schroeder ------------------------ (e-mail address removed)
twitter: @hassan
 
W

Walle Wallen

I need the timeout timer for servers that have crashed, running
extremely slow.
 
H

Hassan Schroeder

I need the timeout timer for servers that have crashed, running
extremely slow.

OK, whatever. You originally said you were checking "if a webserver
is online and operational" -- I wouldn't consider one that's crashed or
can't respond to that request as "operational" :)

Regardless, you still didn't describe the circumstances under which
your script gives inaccurate results.
 
W

Walle Wallen

Hehe, sometimes the timer kicks in, 10 seconds, even if the webserver is
running and is operational.
Thanks for your responds.

//Walle
 
H

Hassan Schroeder

Hehe, sometimes the timer kicks in, 10 seconds, even if the webserver is
running and is operational.

So, I'm confused -- why do you have a 10-second timer if you know
that some of your servers respond more slowly than that, and that's
OK by your definition of "operational" ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top