Results 1 to 12 of 12
-
09-02-2007, 12:57 AM #1Junior Guru Wannabe
- Join Date
- Jan 2005
- Posts
- 34
simple perl progam to save server load every 30 minutes to a file
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);
}
-
09-02-2007, 01:49 AM #2Web Hosting Master
- Join Date
- Apr 2003
- Location
- Canada
- Posts
- 587
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.Mike
cPanel/WHM scripts at Premier Website Solutions (all your website needs)
Support young figure skaters in training. juniorskaters.com
-
09-02-2007, 01:54 AM #3Retired Moderator
- Join Date
- Mar 2004
- Location
- Singapore
- Posts
- 6,990
This seems better in the Technical Forum. Moved.
-
09-02-2007, 06:11 AM #4Newbie
- Join Date
- Aug 2007
- Posts
- 10
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.
-
09-02-2007, 11:32 AM #5Web Hosting Evangelist
- Join Date
- Apr 2003
- Location
- Melbourne, AU
- Posts
- 539
Don't bother reinventing the wheel. This is one of the many metrics that sysstat collects.
WK Woon
CTO | http://www.aflexi.net - A flexible Network
Building the next generation CDN platform - DEMO .... coming soon
-
09-02-2007, 01:07 PM #6Newbie
- Join Date
- Aug 2007
- Posts
- 10
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.
-
09-02-2007, 01:28 PM #7Greece
- Join Date
- Jan 2004
- Location
- Greece
- Posts
- 2,211
Here is another example:
Code:#!/bin/bash up=`uptime`; echo $up >> /home/shell/chris/public_html/server_load.txt up=`echo $up|awk '{split($0,a,"average:"); print a[2]}'` #echo $up; a=`echo $up|awk '{split($0,a,","); print a[1]}'|awk '{split($0,a,"."); print a[1]}'` b=`echo $up|awk '{split($0,a,","); print a[2]}'|awk '{split($0,a,"."); print a[1]}'` c=`echo $up|awk '{split($0,a,","); print a[3]}'|awk '{split($0,a,"."); print a[1]}'` x=0; if [ $a -gt 1 ]; then x=$(expr $x + 1); fi if [ $b -gt 1 ]; then x=$(expr $x + 1); fi if [ $c -gt 1 ]; then x=$(expr $x + 1); fi if [ "$x" -eq 3 ]; then mail -s "Home Server $up" chris@cretaforce.gr < /home/shell/chris/public_html/server_load.txt; fi #if [ "$x" -eq 3 ]; then killall -9 mutella; fi echo "/home/shell/chris/scripts/load.sh >/dev/null 2>&1" | at now + 15 min
-
09-02-2007, 01:34 PM #8Newbie
- Join Date
- Aug 2007
- Posts
- 10
Nice one, with email functionality.
Then again, not something you would want to quickly hack out w/out internet, or is it?
-
09-02-2007, 04:21 PM #9WHT Addict
- Join Date
- Sep 2005
- Posts
- 150
wrong section .
-
09-03-2007, 02:05 AM #10Web Hosting Evangelist
- Join Date
- Apr 2003
- Location
- Melbourne, AU
- Posts
- 539
WK Woon
CTO | http://www.aflexi.net - A flexible Network
Building the next generation CDN platform - DEMO .... coming soon
-
09-03-2007, 02:26 AM #11WebHosting Master
- Join Date
- Dec 2006
- Posts
- 4,151
MRTG records everything including server load every 5 minutes.
-
09-03-2007, 02:27 AM #12Newbie
- Join Date
- Sep 2005
- Location
- Frankfurt/Germany
- Posts
- 29
There is a BSD program called 'bsdsar', you might want to take a look at.
googlebit.com/bsdsar/