用ZABBIX监控F5 TMM Usage

来源:互联网 发布:python help 退出 编辑:程序博客网 时间:2024/04/27 21:28

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供柔软的通知机制以让系统管理员快速定位/解决存在的各种问题。

 

监控F5 TMM Usage需要计算的,来自官方文档

1.
Poll the OID sysMultiHostCpuUser (.1.3.6.1.4.1.3375.2.1.7.5.2.1.4) twice, at a 10-second interval.
This results in two values, <sysMultiHostCpuUser1> and <sysMultiHostCpuUser2>.

Note: Although this example uses an interval of ten seconds, the interval can actually be any duration that you choose.
2.
Calculate the delta of the two poll values:
<DeltaCpuUser = sysMultiHostCpuUser2 - sysMultiHostCpuUser1
3.
Repeat steps one and two for each OID pertaining to the CPU[0-n] graph metric.
4.
Calculate the value of the CPU[0-n] graph metric using the calculation shown in Table 15.14.

Table 15.14 Required calculations for interpreting metrics on CPU use
Performance Graph
(Configuration utility)
Graph Metric
Required calculations for CPU use
 
 
CPU Usage
CPU[0-n]
(<DeltaCpuUser> + <DeltaCpuNice> + <DeltaCpuSystem>) / (<DeltaCpuUser> + <DeltaCpuNice> + <Delta CpuIdle> + <DeltaCpuSystem> + <DeltaCpuIrq> + <DeltaCpuSoftirq> + <DeltaCpuIowait>) *100
TMM CPU Usage
((<DeltaTmTotalCycles> - (<DeltaTmIdleCycles> + <DeltaTmSleepCycles>)) / <DeltaTmTotalCycles>) *100

 

如果直接用ZABBIX自带的SNMP方式来获取相关OID的数值,无法保证再同一时间取3个OID数值,再用这3个OID数值进行计算则会造成较大误差,还会产生负值

所以建议写成脚本方式再直接用ZABBIX调用改脚本,可以避免较大误差。

SHELL监控脚本

#!/bin/bash

#SNMPD_IP=$1
#COMMUNITY=$2


SNMPD_IP=xxx.xxx.xxx.xxx(F5 ip)

COMMUNITY=default

while true; do
        netstat -tunlp | grep :10051 &>/dev/null
        if [ "$?" -eq "0" ]; then
                LAST_TOTAL=`snmpwalk -v 2c -c $COMMUNITY $SNMPD_IP 1.3.6.1.4.1.3375.2.1.1.2.1.41.0 | awk '{print $4}'`
                LAST_IDLE=`snmpwalk -v 2c -c $COMMUNITY $SNMPD_IP 1.3.6.1.4.1.3375.2.1.1.2.1.42.0 | awk '{print $4}'`
                LAST_SLEEP=`snmpwalk -v 2c -c $COMMUNITY $SNMPD_IP 1.3.6.1.4.1.3375.2.1.1.2.1.43.0 | awk '{print $4}'`

                sleep 30(间隔时间越短,精确度越高,但是设定10S有时会出现取值错误,设定30S后可以正常使用)

                CUR_TOTAL=`snmpwalk -v 2c -c $COMMUNITY $SNMPD_IP 1.3.6.1.4.1.3375.2.1.1.2.1.41.0 | awk '{print $4}'`
                CUR_IDLE=`snmpwalk -v 2c -c $COMMUNITY $SNMPD_IP 1.3.6.1.4.1.3375.2.1.1.2.1.42.0 | awk '{print $4}'`
                CUR_SLEEP=`snmpwalk -v 2c -c $COMMUNITY $SNMPD_IP 1.3.6.1.4.1.3375.2.1.1.2.1.43.0 | awk '{print $4}'`

                if [ $CUR_TOTAL -gt $LAST_TOTAL ] && [ $CUR_IDLE -gt $LAST_IDLE ] && [ $CUR_SLEEP -gt $LAST_SLEEP ]; then
                        TOTAL=`echo $CUR_TOTAL $LAST_TOTAL | awk '{print $1-$2}'`
                        IDLE=`echo $CUR_IDLE $LAST_IDLE | awk '{print $1-$2}'`
                        SLEEP=`echo $CUR_SLEEP $LAST_SLEEP | awk '{print $1-$2}'`

                        A=$TOTAL
                        B=`expr $IDLE + $SLEEP`

                        if [ "$A" -ge "$B" ]; then
                                TMMCPU=`echo $TOTAL $IDLE $SLEEP|awk '{print (($1-($2+$3))/$1)*100}'`
                                /目录/zabbix_sender -z xxx.xxx.xxx.xxx(ZABBIX IP) -s "bigip 251" -k "TMM_cpu_used_traps" -o "$TMMC
PU" &>/dev/null
                        fi
                fi
        else
                sleep 30
        fi
done