Cat check_xen_mem.sh#!/bin/shfunction usage () { msg= "$ 0 : use to check xenserver memery usage for nagios " echo "****************************************************" echo -e "\033[1;94m${msg}\033[0m" echo -e "Usage:" echo -e " $0 [-w warning -c critical" echo -e " $0 -w 80 -c 90 " echo " ******************** "}if [ $# -eq 0 ];then warning=0.85 critical=0.95elif [ "$" = "-W" ];then warning= ' echo $2 ' shift shift if [ "$" != "-C" ];then usage exit 1 fi critical= ' echo $2 ' shift shiftelseusage exit 1fistate_ Ok=0state_warning=1state_critical=2state_unknown=3uuid_list= ' Xe host-list | grep uuid | awk ' {print "$ i=1for uuid in " $uuid _listdoeach_mem_total[$i]= ' xe host-param-get param-name= memory-total uuid= $uuid ' each_mem_free[$i]= ' xe host-param-get param-name=memory-free uuid=$ UUID ' let i=i+1donemem_total= ' echo ${each_mem_total[@]} | awk ' {for (i=0;i<NF;i++) total+= $i; print total/1024/1024/1024} ' mem_free= ' echo ${each_mem_free[@]} | awk ' {for (i=0;i<nf;i++) free+= $i;p rint free/1024/1024/1024} ' #mem_usage =$ (((mem_total-mem_ Free)/mem_total) mem_usage= ' awk -v a= $mem _total -v b= $mem _free ' begin{printf '%. 2f ", (A-B)/a }" host_num=${#each_mem_total [@]}performance= "$host _num host; usage: $mem _ usage; free: $mem _free | mem_usage= $mem _usage; $warning; $critical; 0;100;mem_free= $mem _free;;;; " Function cmp_data () {if [ $1 \< $2 ];thenecho "OK $performance" Exit_ Code= $STATE _okelif [ $1 \> $3 ];thenecho "critical $performance" Exit_code= $STATE _ criticalelseecho "warning $performance" exit_code= $STATE _warningfi}cmp_data $mem _usage $ warning $criticalexit $exit _code
This article from "Month Child" blog, declined reprint!
Nagios Monitoring XenServer Memery