# Webserver status, need better approach

**URL:** <https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541>\
**Category:** Ruby\
**Created:** [June 2, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541 "2010-06-02T19:31:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [June 2, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541/1 "2010-06-02T19:31:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [June 2, 2010, 9:09pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541/2 "2010-06-02T21:09:16Z")

</div>

On Wed, Jun 2, 2010 at 10:31 AM, Walle W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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. 🙂

FWIW,

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [June 2, 2010, 9:33pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541/3 "2010-06-02T21:33:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [June 2, 2010, 9:40pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541/4 "2010-06-02T21:40:17Z")

</div>

On Wed, Jun 2, 2010 at 12:33 PM, Walle W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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” 🙂

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

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [June 2, 2010, 11:26pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541/5 "2010-06-02T23:26:48Z")

</div>

On Wed, Jun 2, 2010 at 12:53 PM, Walle W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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” ?

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [June 2, 2010, 9:53pm UTC](https://www.ruby-forum.com/t/webserver-status-need-better-approach/189541/6 "2010-06-02T21:53:50Z")

</div>

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

//Walle
