Simple Load Monitoring Script in BASH/Python/Perl
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)
- 2) Load monitoring script in Python(loadavg.py)
- 3) Load monitoring script in perl(loadavg.pl)
#!/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);
