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 :
#!/bin/sh # 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 ] then kill -9 `cat $PIDFILE` > /dev/null 2>&1 fi echo "$$" > $PIDFILE # send request & check for expected response snmpwalk -v 2c -c community ${IP} .1.3.6.1.4.1.2021.4.5.0 > /var/tmp/monitor/mem_size_${IP}.log snmpwalk -v 2c -c community ${IP} .1.3.6.1.4.1.2021.4.6.0 > /var/tmp/monitor/mem_avail_${IP}.log snmpwalk -v 2c -c community ${IP} .1.3.6.1.4.1.2021.11.11 > /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 fi else echo "The threshold MEMORY has reached for $IP - DOWN" | logger -p local0.debug rm -f $PIDFILE fi
Published Mar 12, 2015
Version 1.0Luis_Araujo_560
Nimbostratus
Joined July 20, 2011
Luis_Araujo_560
Nimbostratus
Joined July 20, 2011
No CommentsBe the first to comment