CPU monitor

Problem this snippet solves:

Pull CPU utilization and use it with an external monitor

How to use this snippet:

I need to start by giving credit to the original post here.All I did was modify that script to match what I need it for. This is the first time I am using an external monitor and it was great to make it work so I thought i should share as someone else might need it. There is probably a better way to do this. If so please share. The original script was tackling CPU and memory utilization as this one is only looking at CPU. And in this particular case, I am taking in account all CPUs (2 of them) on the Box.

You'll have to start with creating a Read Only SNMP Community String that will be use to pull this Data.

Import the script from System/File Management/External Monitor Program File List

Create a new External monitor Local Traffic/Monitor and Type External

Select your previously uploaded script from External program

For Variables, enter DEBUG for name and Value will be the value you chose for "DEB" in the script.

Then you can apply your monitor to the node or pool you choose to.

Code :

# IPv6/IPv4 compatibility prefix (LTM passes addresses in IPv6 format)
IP=`echo ${1} | sed 's/::ffff://'`
PIDFILE="/var/run/`basename ${0}`.${IP}_${PORT}.pid"
# kill of the last instance of this monitor if hung and log current pid
if [ -f $PIDFILE ]
kill -9 `cat $PIDFILE` > /dev/null 2>&1
echo "$$" > $PIDFILE
# send request & check for expected response
#Replace  with your string that need read Only access to the server

snmpwalk -v 2c -c  ${IP} . > /var/tmp/monitor/cpu1_${IP}.log
snmpwalk -v 2c -c  ${IP} . > /var/tmp/monitor/cpu2_${IP}.log
# mark node UP if expected response was received

cpu1=`cat /var/tmp/monitor/cpu1_${IP}.log | cut -f4 -d" "`
cpu2=`cat /var/tmp/monitor/cpu2_${IP}.log | cut -f4 -d" "`

#Check the CPU threshold and make a decision on it
# Replace  with your desire CPU threshold
# Replace  with a number outside the range (0-100). This will allow the threshold to be caught and sent to monitor

if [ "$cpu1" -le "" -a "$cpu2" -le "" ]; then
    echo "UP"
    rm -f $PIDFILE
elif [ "$DEBUG" -eq "" ]; then
    echo "The threshold CPU has reached $cpu1 and $cpu2 for $IP - DOWN" | logger -p local0.debug
    rm -f $PIDFILE

Tested this on version:

Published Sep 08, 2016
Version 1.0

Was this article helpful?

No CommentsBe the first to comment