# vmstat 1 2, 一秒间隔,取两次,因为发现第一次不准确
command[cacti_vmstat]=/usr/bin/vmstat 1 2
/bin/bash <path_cacti>/scripts/bigbig_vmstat_cpu.sh <server_addr>
#!/bin/bash
# bigbig_vmstat_cpu.sh
hostname=$1
result=`/usr/local/nagios/libexec/check_nrpe -H $hostname -c cacti_vmstat | tail -n 1`
# proc
running=`echo $result | awk '{print $1}'`
busy=`echo $result | awk '{print $2}'`
#echo -n "running:$running busy:$busy "
# memory
swapd=`echo $result | awk '{print $3}'` && ((swapd=$swapd*1024))
free=`echo $result | awk '{print $4}'` && ((free=$free*1024))
buff=`echo $result | awk '{print $5}'` && ((buff=$buff*1024))
cache=`echo $result | awk '{print $6}'` && ((cache=$cache*1024))
#echo -n "swapd:$swapd free:$free buff:$buff cache:$cache "
# swap
si=`echo $result | awk '{print $7}'` && ((si=$si*1024))
so=`echo $result | awk '{print $8}'` && ((so=$so*1024))
#echo -n "si:$si so:$so "
# io
bi=`echo $result | awk '{print $9}'`
bo=`echo $result | awk '{print $10}'`
#echo -n "bi:$bi bo:$bo "
# system
in=`echo $result | awk '{print $11}'`
cs=`echo $result | awk '{print $12}'`
#echo -n "in:$in cs:$cs "
# cpu
us=`echo $result | awk '{print $13}'`
sy=`echo $result | awk '{print $14}'`
id=`echo $result | awk '{print $15}'`
wa=`echo $result | awk '{print $16}'`
st=`echo $result | awk '{print $17}'`
echo -n "sdfsdf:123 user:$us system:$sy idle:$id wait:$wa stealt:$st sdf sdf sdf sdf "
http://pan.baidu.com/s/1dD34F1B
#!/bin/bash
ip=$1
# 判断是否存在,如果存在就退出
hostfind=`php add_graphs.php --list-hosts | grep $ip$ | wc -l`
[ $hostfind -eq 1 ] && ( echo "host $ip 已经存在 ";exit 0 )
# 添加hosts
php add_device.php --description=$ip --ip=$ip --template=9
hostid=`php add_graphs.php --list-hosts | grep $ip$ | awk '{print $1}'`
echo $hostid
#exit 0
#[[ $hostid -gt 70 ]] || exit 0
# 开始画vmstat
php add_graphs.php --graph-type=cg --graph-template-id=64 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=73 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=74 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=75 --host-id=$hostid --input-fields="server_addr=$ip"