Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How do you check the status of a given server?

by techgrrl (Acolyte)
on Feb 20, 2013 at 04:51 UTC ( #1019705=note: print w/ replies, xml ) Need Help??


in reply to How do you check the status of a given server?

I think roboticus said it fairly well, check the services it provides.

Without knowing more about the server it is hard to get more specific.

To add a little more detail. You can ping most servers to see if they have a healthy network stack, either by using system calls or backticks (not my first choice) or by using Net::ICMP. To use the `backtick` method enclose any valid system command in backticks and the output of the command will be assigned to the variable. It is messy, and you often lose return codes from the commands, but it is simple.

#!/usr/bin/perl $result = `/sbin/ping -q -c 5 www.google.com | grep loss`; if ($result =~ /(\d+\.\d+\%) packet loss/) { print "We lost $1 of the traffic\n"; }

To use any of the ICMP modules such as Net::Ping let your friend CPAN explain everything, but feel free to ask again when you have a more specific question.

You can also monitor a server via SNMP. Most servers respond to the OID system.sysuptime.0.

If you don't know what an OID is, read the Net::SNMP documentation. In order to use SNMP, you'll need to find a SNMP package and read the docs, something like Net::SNMP or SNMP::Simple. From a Unix host you can also call the Net-SNMP using the system call or `snmpget $args` like in the above code example, but again, that is probably not the best way to do it. Generally I prefer to use modules like Net::SNMP.

If the server has a web server running, using LWP::Simple to get a test document is pretty easy.

If you have CGI enabled on the web server, you can write a CGI to run some health checks, and then use LWP::Simple to get the web page.

For example if you have a perl script called health.cgi, you can run any commands you want to check the servers health and print out valid html, and then from another machine run a perl script using LWP::Simple to get http://your-server.com/health.cgi

Think about those things to get started, and if you have more specific questions, feel free to ask again.

I hope this helps you get started.


Comment on Re: How do you check the status of a given server?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019705]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-07-29 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (217 votes), past polls