Small script to acquire combined cpu load (average) from remote server. I required to acquire ESXI multicore cpu load to plot mrtg graph.
#!/bin/bash # Script to query ESXI server #set -x HOST="$1" SNMP_STRING="public" TMP_HOLDER="/tmp/cpuinfo.$HOST" OID="hrProcessorLoad." MIB="/cfg/mibs/HOST-RESOURCES-MIB" snmpwalk -v2c -c $SNMP_STRING -m "$MIB" $HOST |grep $OID | awk '{print $4}' > $TMP_HOLDER CPU_CORE=`cat $TMP_HOLDER | wc -l` CPU_LOAD_SUM=`cat $TMP_HOLDER | awk '{ sum += $1 } END { print sum }'` CPU_LOAD_FINAL=`echo "scale=2; $CPU_LOAD_SUM/$CPU_CORE" | bc -l` echo $CPU_LOAD_FINAL echo $CPU_LOAD_FINAL
Result:
(following result is average value of my esxi server which have 2 physical processor with 6 cores each, so virtually there are 24 cores for ESXI)
root@linux:/temp# ./cpu_load.sh 10.0.0.1
6.70
6.70
CFG example:
ESXI Server -10.0.0.1- CPU Utilization ### Target[esxi_cpu_1010.0.0.1]: `/temp/cpu_load.sh 10.0.0.1` Options[esxi_cpu_1010.0.0.1]: growright, gauge, integer, noo MaxBytes[esxi_cpu_1010.0.0.1]: 100 LegendI[esxi_cpu_1010.0.0.1]: Total CPU Cores Used % LegendO[esxi_cpu_1010.0.0.1]: Legend1[esxi_cpu_1010.0.0.1]: Total CPU Cores Used % Legend2[esxi_cpu_1010.0.0.1]: Title[esxi_cpu_1010.0.0.1]: ESXI Server -10.0.0.1- CPU Load % PageTop[esxi_cpu_1010.0.0.1]: <h1>ESXI Server -10.0.0.1- CPU Load %</h1> Unscaled[esxi_cpu_1010.0.0.1]: ymwd ShortLegend[esxi_cpu_1010.0.0.1]: % YLegend[esxi_cpu_1010.0.0.1]: % CPU Used Colours[esxi_cpu_1010.0.0.1]: RED#ff4f27,DIRTY YELLOW#E6B420,RED#ff4f27,DIRTY YELLOW#E6B420
J.
Filed under: Linux Related
