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
#!/bin/bash
export _loadavg=$( cat /proc/loadavg | awk ‘{ print $1}’)
echo “Load Average:$_loadavg on `date` ” >> /var/log/load.log
#!/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()
#!/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);
One Comment on “Simple Load Monitoring Script in BASH/Python/Perl”
This is crappy code for python there is much better way to do that (parsing /proc/loadvg)
Leave a Reply