Simple script to monitor Xen node utilization with email alert

Here is a simple script that utilizes xentop to monitor your Xen server. You can schedule this via cron to run every X minutes to track the load average and if gets too high, it will email you (be sure you change your-emailid to your actual email address)

#!/bin/bash

loadavg=`uptime | awk '{print $10}'`

process=`nproc`

# bash doesn't understand floating point

# so convert the number to an interger

thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`

if [ "$thisloadavg" -ge "$process" ]; then

echo "Busy - Load Average $loadavg ($thisloadavg) "
host=`hostname`
top=`top -bn 1 | head -20`
vmstat=`xentop -b -i 3 | sort -r -nk4 | head -15 | awk '!_[$1]++'`
stat=`netstat -ntuplaee`
echo -e "Top out:\n ${top}\n\nNetstat out:\n${stat}\n\nVMStat Out:\n${vmstat}" | mail -s "Load Alert from ${host}" your-emailid
else

echo "Okay - Load Average $loadavg ($thisloadavg) "
fi
See also  4 Free Ways to Convert a PDF to a Plain Text File on Linux

Support us & keep this site free of annoying ads.
Shop Amazon.com or Donate with Paypal

Leave a Comment