External Health monitor - check SNMP info from servers
Hello,
I´m having the following requierement:
Need to get the snmp information of the servers I´m load balancing, and when the CPU and MEMORY pass over 90%, put this server on maintenance mode, so won´t receives new clients, but still maintains the connection for currents clients.
Then, after the CPU and memory decreases below 70%, the server will pass again to a Enable status.
I have this template, but is only for enable - disable servers.
#! /bin/bash
CPU_OID=.1.3.6.1.4.1.22610.2.4.1.3.5.0
MEM_USAGE_OID=.1.3.6.1.4.1.22610.2.4.1.2.2.0
MEM_TOTAL_OID=.1.3.6.1.4.1.22610.2.4.1.2.1.0
CPU=
MEM_USAGE=
MEM=
THRESH_CPU=80
THRESH_MEM=90
echo "$CPU"
echo "$MEM"
if [ $CPU -lt ${THRESH_CPU} -a $MEM -lt ${THRESH_MEM} ] ; then
#UP
exit 0
else
#DOWN
exit 1
fi
I´m having the following requierement:
Need to get the snmp information of the servers I´m load balancing, and when the CPU and MEMORY pass over 90%, put this server on maintenance mode, so won´t receives new clients, but still maintains the connection for currents clients.
Then, after the CPU and memory decreases below 70%, the server will pass again to a Enable status.
I have this template, but is only for enable - disable servers.
#! /bin/bash
CPU_OID=.1.3.6.1.4.1.22610.2.4.1.3.5.0
MEM_USAGE_OID=.1.3.6.1.4.1.22610.2.4.1.2.2.0
MEM_TOTAL_OID=.1.3.6.1.4.1.22610.2.4.1.2.1.0
CPU=
/usr/bin/snmpget -v2c -c public -OqUv ${HM_SRV_IPADDR} ${CPU_OID}
MEM_USAGE=/usr/bin/snmpget -v2c -c public -OqUv ${HM_SRV_IPADDR} ${MEM_USAGE_OID}
MEM_TOTAL=/usr/bin/snmpget -v2c -c public -OqUv ${HM_SRV_IPADDR} ${MEM_TOTAL_OID}
MEM_USAGE=
expr $MEM_USAGE \* 100
MEM=
expr $MEM_USAGE / $MEM_TOTAL
THRESH_CPU=80
THRESH_MEM=90
echo "$CPU"
echo "$MEM"
if [ $CPU -lt ${THRESH_CPU} -a $MEM -lt ${THRESH_MEM} ] ; then
#UP
exit 0
else
#DOWN
exit 1
fi
Tagged:
0
Comments
Here is an example of a Shell script for SNMP-based load balancing. This script uses the results from queries to the UC-SNMP-MIB MIB module.
#!/bin/sh
dst="$HM_SRV_IPADDR"
#dst="$HM_SRV_IPADDR:$HM_SRV_PORT"
# Community String
community="public"
# UC-SNMP-MIB::extResult.1
oid=".1.3.6.1.4.1.2021.8.1.100.1" (Note: This has to be updated based on server OID information)
function check_value {
echo "$output"
value=
echo $output | sed 's/INTEGER: //'
echo "value" = "$value"
if [[ "$value" =~ "^[[:digit:]]*$" ]]; then
# echo "digit string"
if [ $value -ge 0 -a $value -lt 125 ]; then
echo "Good"
exit $value
fi
fi
}
echo "/usr/bin/snmpget -v2c -c \"$community\" -Ov \"$dst\" $oid"
output=$(/usr/bin/snmpget -v2c -c "$community" -Ov "$dst" $oid)
if [ 0 != $? ]; then
exit -1
fi
check_value
# success
echo "Mark server down"
exit -1