在宿主机上安装collectd工具后,可以通过collectd工具来获取宿主机上的虚拟机的cpu,memery,if-traffic等数据。可以通过nagios监控脚本来实现对这些数据监控。
以下是一个简单的监控虚拟机内存脚本:
#!/bin/bash #Desc:to check memory about vm instance STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 COLLECTD_HOME=/usr/local/collectd COLLECTD_CTL=$COLLECTD_HOME/bin/collectdctl vmname=$1 function usage() { msg="$0 : use to check vm memery usage for nagios" echo "****************************************************" echo -e "\033[1;94m${msg}\033[0m" echo -e "Usage:" echo -e " $0 [-w warning_value -c critical_value] vm_name" echo -e " $0 vmname " echo "****************************************************" } if [ $# -eq 0 ];then usage exit 1 fi mem_used=`$COLLECTD_CTL getval $vmname/virt-$vmname/memory-rss | awk -F "=" ‘{print $2}‘ | awk ‘{printf("%.1f\n",$0/1024/1024)}‘` data="mem=$mem_used" if [ -z $mem_used ];then echo "unkown: fail to find vm_instance!" exit $STATE_UNKNOWN else echo "ok - used : ${mem_used}MB | ${data}MB" exit $STATE_OK fi
时间: 2024-10-19 04:45:03