Results 1 to 12 of 12
  1. #1
    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);
    }

  2. #2
    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

  3. #3
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    6,990
    This seems better in the Technical Forum. Moved.

  4. #4
    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.

  5. #5
    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

  6. #6
    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.

  7. #7
    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

  8. #8
    Nice one, with email functionality.

    Then again, not something you would want to quickly hack out w/out internet, or is it?

  9. #9

  10. #10
    Join Date
    Apr 2003
    Location
    Melbourne, AU
    Posts
    539
    Quote Originally Posted by gratemyl View Post
    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.
    In the context of WHT, that situation may be the exception rather than the norm
    WK Woon
    CTO | http://www.aflexi.net - A flexible Network
    Building the next generation CDN platform - DEMO .... coming soon

  11. #11
    Join Date
    Dec 2006
    Posts
    4,151
    MRTG records everything including server load every 5 minutes.

  12. #12
    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/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •