Web Hosting Talk







View Full Version : Load average on dedicated servers


zoli
07-05-2002, 03:24 AM
Hello guys,

I have 2 dedicated servers (just my own sites) and I'd like to ask you a question.
Can you recommend some good load checker that will run from crontab to test the load average on server, if it is high (4 or up) take some proper actions?

Thanks in advance for your help.

sonic
07-07-2002, 05:29 AM
you will need to write a script for that

InterServ-JB
07-07-2002, 12:59 PM
Yep! If you need someone to code for you, try http://www.programmingbids.com I highly recommend their service and have gotten quality prorgamming services.

phpjames
07-07-2002, 01:09 PM
This wouldnt be too hard to do but I wouldnt know what proper actions you want to take. I think that is case dependent. You would have to actually decide what you wanted to kill.

Writing a set of bash scripts to check the load and say email you if the load is too high would be fairly simple. Good luck.

fog
07-07-2002, 01:25 PM
Writing the script should actually be quite easy.

The thing, like phpjames said, is... Well, what are you going to do? I fear that you might be trying to kill the most intensive process or something to that effect. I think this would be a bad idea -- suppose you get a sudden traffic surge, and Apache becomes very busy serving the thousands of hits. Having Apache suddenly killed isn't going to help things at all.

However, this is mere speculation on my part of what you're trying to do. If you want to have it simply fire an e-mail off to you, then this is a *good* idea.

I'm not the best programmer, but now you've got me curious... I'm gonna try to whip something up, although I'll probably never end up with something usable.

fog
07-07-2002, 02:11 PM
Okay, so I did it. As I'm not sure how familiar you are with Perl or anything, I've given my code gobs of documentation. Also note that this script needs to be on a UNIX box (Debian Linux here, but it shouldn't matter?) with Perl installed. (Experienced eyes when it comes to Perl are encouraged to look over my code.)

Note that, since I didn't know what action you wanted to take, I merely have it print a message to the console, but I've included an (excessively lengthy) comment detailing what you might want to do.

One thing to remember is that this script is calling a shell command every time it runs. Security considerations aside, this will increase your process ID count by one every time it runs (well, two, if you count the script itself running...?). There aren't necessarily any adverse affects of this, just that when you run a process, it's ID number might be something like "30,000" as opposed to "142" or something on a system that's very tightly-controlled and never has much run. I don't think this really matters in the least, it's just a loony personal preference of mine.

This code is provided without any warranty or anything, use it at your own "risk." I'd probably drop dead of a heart attack if it didn't work on your box, but you know, all that legal garbage... :rolleyes:

Lastly... You need to put this in crontab. I don't know how, I'm more of a "programmer" than a systems administrator. :( (It should be easy, though.) Let me know if you need any further help, I'd be glad to try to help out.

Oh, almost forgot -- rename this to "zoli.pl" (I suppose it'd work just fine if you don't change it, but you'll confuse the heck out of everyone if you don't rename it...)

fog
07-07-2002, 02:11 PM
Ignore this message... WHT kept timing out as I went to post this, and it ended up getting posted twice... I can't delete this, so just ignore it. :)

blazenet
07-07-2002, 02:21 PM
very nice fog...

But I assume your script doesn't work on freebsd?

AcuNett
07-07-2002, 02:23 PM
Webmin has a nice feature for that. You can also check other things such as apache, xinetd, mysql, qmail, sendmail etc.

fog
07-07-2002, 02:40 PM
Originally posted by blazenet
But I assume your script doesn't work on freebsd?

I don't have access to a FreeBSD box, but I would *guess* it would work, assuming that it has Perl installed. The real platform-dependence just comes from calling the "uptime" command, which I believe existed before Linux and is a generic UNIX tool. I could be wrong.

If you have FreeBSD, you can try this out, it really shouldn't be able to cause any harm.

zoli
07-07-2002, 02:57 PM
Hi fog, nice script, I will try to test it by tommorrow. Right now, my server only has about 0.15-0.20.
I tried to add 0.1 to $max then I accessed the script through perl testload.pl, but it did not display the message: "Danger! High load average!" Any suggestion?

Thanks again.

Zoltan

viGeek
07-07-2002, 03:03 PM
Here is a very simple & small php script. Upload it, and point your browser to it. It tells you.......

Your uptime
Your Kernel Version
Your Current Load
Your Current PRoc. running....


Note: Save file as "whatever.php". file is in text format so I could upload it/.

fog
07-07-2002, 03:53 PM
Zoli, I'm not exactly sure why it's not working. Could you paste (or PM me, doesn't really matter which) the output of running "uptime" in a shell? Running uptime should spit out a bunch of junk, ending in 3 load averages. My script takes the middle one; is that also over 0.1? I'm also wondering if maybe your "uptime" has a different format than mine? If you can just give me the output, I'll see if I can figure out what's up.

BTW, vigor, I tried your script on my site, it doesn't work (I think it's a problem on my end, but I was just poking around with your script; I only have Apache going on my 'desktop,' so it's not of much use for me). However, the code is pretty interesting; makes me want to rewrite my script to avoid its dependence on "uptime"... I think I might just do that now. :)

fog
07-07-2002, 04:12 PM
vigor posted a PHP script, which gave me a better idea... My script now reads /proc/loadavg instead of calling "uptime," which makes for one less possible way to fail, and it's better programming practice anyway.

I've named this one zoli2.pl.txt; rename it to zoli2.pl or something. (Don't overwrite the other one, in case this doesn't work.) In this one, I changed the threshold from 4.0 to 0.01, so it's almost guaranteed to "go off."

Let me know if this one works better.