Tuesday, February 17, 2009

Remote disk space monitor

The following is a poor man's disk space monitor script.
"ssh id@host df -h " is the core of the script. It relies on SSH RSA authentication so that the remote "df" can work like local.


#!/bin/ksh
homedir=`dirname $0`
RUN_DATE_LONG=$(date +'%Y%m%d')
LOGFILE=${homedir}/diskmon_log.$RUN_DATE_LONG

HOSTS="192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 "

alert=90
alert_email="admin@foo.com"
typeset -i email=0

function rdf
{
echo "$1 is sshing into $2 doing a df......." >> $LOGFILE
ssh $1@$2 df -hP | grep -vE '^Filesystem' | awk '{print $4 " " $5 " " $1 " " $2}' | while read line;
do
typeset -i used=$(echo $line | awk '{print $1}' | cut -d "%" -f 1)
if [[ $used -ge $alert ]]; then
email=1
echo $line >> $LOGFILE
fi
done
echo "ssh done......." >> $LOGFILE
}



for h in $HOSTS
do
rdf sshid $h
done


if [[ ${email} -eq 1 ]]; then
echo "alert email will be setnt" >> $LOGFILE
# put whatever mailer you use here
fi

Monday, February 9, 2009

Dtrace could be the secret weapon

I had this vision of setting up a high end consulting firm which only serves some hard problem such as performance. One of secret weapon is Dtrace.

DTrace for linux: http://www.crisp.demon.co.uk/tools.html

DTrace with Python: http://blogs.sun.com/levon/entry/python_and_dtrace_in_build