Portal Home > Knowledgebase > Articles Database > simple perl progam to save server load every 30 minutes to a file


simple perl progam to save server load every 30 minutes to a file




Posted by digirave, 09-02-2007, 12:57 AM
although there are much better ways, for quick and dirty i use the following perl script(created by me) to save server load every 30 minutes to a log file i just keep it running in the background(probably would be more effective using cron) #!/usr/bin/perl while(1) { $w = `w`; #print $w; $w =~ /load average: (.+)\n/; $log = $1; my ($sec, $min, $hour, $mday, $mon, $year) = localtime; my $rightnow = sprintf("%04d-%02d-%02d %02d:%02d:%02d ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec); $log = $rightnow . ": " . $log ."\n"; open (OUTFILE, ">>top_logfile.txt"); print OUTFILE "$log\n"; close (OUTFILE); #sleep for 30 minutes sleep(1800); }

Posted by Premier, 09-02-2007, 01:49 AM
Definitely better to just have it run once and use cron to run it every 30 minutes. With the current method, if it stops for any reason, it's done until you restart it. I had a script to monitor domain names that I ran that way a few years ago and then switched to a cron job.

Posted by boonchuan, 09-02-2007, 01:54 AM
This seems better in the Technical Forum. Moved.

Posted by gratemyl, 09-02-2007, 06:11 AM
Aren't there quicker ways to do this? How about just running a cron which places qx{w} output into a file (appending of course)? That would be even more dirty, but would work just as well, and would be even shorter.

Posted by wKkaY, 09-02-2007, 11:32 AM
Don't bother reinventing the wheel. This is one of the many metrics that sysstat collects.

Posted by gratemyl, 09-02-2007, 01:07 PM
Well, we are interested in quick-and-dirty hacks, possibly when no internet connection is available - so sysstat would not be available. That's the point.

Posted by CretaForce, 09-02-2007, 01:28 PM
Here is another example:

Posted by gratemyl, 09-02-2007, 01:34 PM
Nice one, with email functionality. Then again, not something you would want to quickly hack out w/out internet, or is it?

Posted by Tech4server, 09-02-2007, 04:21 PM
wrong section .

Posted by wKkaY, 09-03-2007, 02:05 AM
In the context of WHT, that situation may be the exception rather than the norm

Posted by tsj5j, 09-03-2007, 02:26 AM
MRTG records everything including server load every 5 minutes.

Posted by mainlink, 09-03-2007, 02:27 AM
There is a BSD program called 'bsdsar', you might want to take a look at. googlebit.com/bsdsar/



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Issues with HostGator (Views: 776)
PHP arithmetic issue (Views: 703)
for resellers (Views: 711)
LFD Failures - cPanel (Views: 724)


Language: