SNMP Monitor for CPU and Memory Threshold

Problem this snippet solves:

This external monitor uses the threshold of CPU and Memory for classify the pool member as available or down. I calculated the results of snmp to have the desired percentage Follow the steps: 1. Create the arquive called "script_snmp" in "/config/monitors/" and copy the script below: 2. Give permission by execution: #chmod 755 script_snmp; 3. Create folder called "monitor" in "/var/tmp"; 4. In LTM/Monitors, click in "CREATE" 5. write the monitor name 6. Choice the monitor external type 7. Set the runtime 8. Set the path of script 9. In variable, set the value: DEBUG=1 10. Click in "FINISH" 11. Set the monitor the Pool

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
snmpwalk -v 2c -c community ${IP} . > /var/tmp/monitor/mem_size_${IP}.log
snmpwalk -v 2c -c community ${IP} . > /var/tmp/monitor/mem_avail_${IP}.log
snmpwalk -v 2c -c community ${IP} . > /var/tmp/monitor/cpu_${IP}.log
# mark node UP if expected response was received
size=`cat /var/tmp/monitor/mem_size_${IP}.log | cut -f4 -d" "`
avail=`cat /var/tmp/monitor/mem_avail_${IP}.log | cut -f4 -d" "`
expr $avail \* 100 / $size > /var/tmp/monitor/percentage_${IP}
memory=`cat /var/tmp/monitor/percentage_${IP}`
cpu=`cat /var/tmp/monitor/cpu_${IP}.log | cut -f4 -d" "`
if [ "$memory" -le "85" ]; then
    if [ "$cpu" -ge "20" ]; then
       echo "UP"
       rm -f $PIDFILE
    elif [ "$DEBUG" -eq "1" ]; then
          echo "The threshold CPU has reached for $IP - DOWN" | logger -p local0.debug
          rm -f $PIDFILE
    echo "The threshold MEMORY has reached for $IP - DOWN" | logger -p local0.debug
          rm -f $PIDFILE
Published Mar 12, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment