Ronald A. Richardson.com
stitches don’t keep the pain in, just let it heal over time, and you’ll be alright



Simple Load Monitoring Script in BASH/Python/Perl
comment No Comments Written by Ronald on June 29, 2008 – 9:38 pm

Here is a simple Load monitoring / logging script . This will log the load in /var/log/load.log . You can execute the script as follows,

chmod +x /root/loadavg.sh

Now add it as cron

*/5 * * * * /root/loadavg.sh

  • 1) Load monitoring script in BASH(loadavg.sh)
  • #!/bin/bash

    export _loadavg=$( cat /proc/loadavg | awk ‘{ print $1}’)

    echo “Load Average:$_loadavg on `date` ” >> /var/log/load.log

  • 2) Load monitoring script in Python(loadavg.py)
  • #!/usr/bin/env python

    import os,commands

    loadavg=commands.getoutput(”cat /proc/loadavg|awk ‘{ print $1}’”)

    _date=commands.getoutput(”date”)

    f = open(’/var/log/load.log’, ‘aw’)

    f.writelines( “Load average :” +loadavg+” on “+ _date+”n”)

    f.close()

  • 3) Load monitoring script in perl(loadavg.pl)
  • #!/usr/bin/perl

    my $ld=`cut -d’ ‘ -f1 /proc/loadavg`;

    my $lavg=chomp($ld);

    my $D_ate=`date`;

    open (LOG, ‘>>/var/log/load.log’);

    print LOG “Load Average:$ld on $D_ate”;

    close (LOG);

If you enjoyed the article, why not subscribe?

Post a Comment

About The Author: Ronald

I am Ronald A. Richardson, champion of the underworld!

Want to subscribe?

 Subscribe in a reader Or, subscribe via email:
Enter your email address: