Webserver status, need better approach

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

On Wed, Jun 2, 2010 at 10:31 AM, Walle W. [email protected]
wrote:

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.

Under what circumstances does it fail?

return false
end

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 == “200”
end

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

FWIW,

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

On Wed, Jun 2, 2010 at 12:33 PM, Walle W. [email protected]
wrote:

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” :slight_smile:

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

On Wed, Jun 2, 2010 at 12:53 PM, Walle W. [email protected]
wrote:

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” ?

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

//Walle