xenserver 主机本地磁盘IOPS 及 VMIOPS监控

如出现上图情况,xenserver需要打补丁,rrd2csv监控不全

#!/bin/sh
#this script for get xenserver 6.5 7.0  storage I/O
#2016/12/21 hayden
#send xen-host-iops.sh to xenserver use ftp or ssh first  ./xen-host-iops.sh
#yelang007sheng@163.com

log=`date "+%H_%M_%S"`

get_host_uuid(){

host_uuid=`xe host-list |grep uuid |awk -F\: '{print $2}' |sed 's/ //g'`
#host_uuid=`xe host-list --minimal`
sleep 1

}

get_local_sr_uuid(){

l_sr_uuid=`xe sr-list content-type=user |grep uuid |awk -F\: '{print $2}' |sed 's/ //g'`
#l_sr_uuid=`xe sr-list content-type=user --minimal`
l_sr_uuid8=`echo $l_sr_uuid |awk -F\- '{print $1}'`
}

get_host_local_sr_iops_avg(){

rrd2csv AVERAGE:host:"$host_uuid":iops_total_"$l_sr_uuid8" >host_sr_iops_avg_"$log" & >/dev/null
#rrd2csv AVERAGE:host:"$host_uuid":cpu_avg >host_cpu_avg_"$log" & >/dev/null
rrd2csv_pid=$!

}

monitor_time(){
while :
do
    read -p "Please input a monitor time:[ exp> 60s or 5m or 1h or 1d ] " time
    # 
    if [ `echo "${time:0:${#time}-1}" |grep -c '[^0-9]'` -ne 0 ] || [ `echo "${time:0-1}" |grep -c '[smhd]'` -ne 1 ]; then
        echo "Input monitor time error!!!"
        continue
    else
        if [ "${time:0:${#time}-1}" -gt 0 ]; then
            break
        else
            echo "Input monitor time error!!!"
            continue
        fi
    fi
done
}

#main
echo "This script for get Host Local Storage IOPS ......"
monitor_time
get_host_uuid
get_local_sr_uuid
get_host_local_sr_iops_avg
echo "Monitor start ... Please wait $time "
sleep $time
sleep 1
kill -9 $rrd2csv_pid >/dev/null 2>&1
sleep 2
cp host_sr_iops_avg_"$log" iops_temp_"$log"
sed -i '1d' iops_temp_"$log"

cat iops_temp_"$log" |awk -F\, '{print $2}' |sed 's/ //g' | sort -n >temp_"$log"
min_iops_t=`head -n 1 temp_"$log"`
min_iops=`echo "scale=2; $min_iops_t"|bc |awk '{printf "%.2f", $0}'`
max_iops_t=`tail -n 1 temp_"$log"`
max_iops=`echo "scale=2; $max_iops_t"|bc |awk '{printf "%.2f", $0}'`
count_temp=`cat temp_"$log" |wc -l`

sum=0
for i in `cat temp_"$log"`
do
    sum=`echo $sum + $i |bc`
done


avg_iops_t=`echo "scale=4; $sum / $count_temp "|bc |awk '{printf "%.4f", $0}'`
avg_iops=`echo "scale=2; $avg_iops_t"|bc |awk '{printf "%.2f", $0}'`

echo Host["$host_uuid"] LocalSR["$l_sr_uuid"] min_iops="$min_iops" |tee host_sr_iops_"$log"
echo Host["$host_uuid"] LocalSR["$l_sr_uuid"] max_iops="$max_iops" |tee -a host_sr_iops_"$log"
echo Host["$host_uuid"] LocalSR["$l_sr_uuid"] avg_iops="$avg_iops" |tee -a host_sr_iops_"$log"

mkdir -p /tmp/host_iops_"$log"
mv host_sr_iops_avg_"$log" host_sr_iops_"$log" /tmp/host_iops_"$log" 
rm -rf  iops_temp_"$log" temp_"$log"  
#!/bin/sh
#this script for get xenserver 6.5 7.0 VM storage I/O
#2016/12/21 hayden

#use tool rrd2csv 
#rrd2csv AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_read ,AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_write ,AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_total
#rrd2csv AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_total

log=`date "+%H_%M_%S"`

get_host_uuid(){

host_uuid=`xe host-list |grep uuid |awk -F\: '{print $2}' |sed 's/ //g'`
sleep 1

}

get_local_sr_uuid(){
  #get_local sr uuid
  l_sr_uuid=`xe sr-list content-type=user |grep uuid |awk -F\: '{print $2}' |sed 's/ //g'`
  l_sr_uuid8=`echo $l_sr_uuid |awk -F\- '{print $1}'`
}

get_vm_uuid(){
# get running VM uuid
  xe vm-list power-state=running |grep uuid |awk -F\: '{print $2}' |sed 's/ //g' >vm_uuid.tmp
}


get_domain_uuid(){
  # get control domain UUID
  domain_uuid=`xe vm-list dom-id=0 |grep uuid |awk -F\: '{print $2}' |sed 's/ //g'`
}

rrd2cmd(){
  get_host_uuid
  get_local_sr_uuid
  get_domain_uuid
  get_vm_uuid
  #delete domain uuid from running VM uuid
  sed -i /"$domain_uuid"/d vm_uuid.tmp
  
  #分别在每行的行首行添加“AVERAGE:vm” 在行尾添加“:vbd_xvda_iops_total ,”关键字  
  sed -i '/./{s/^/AVERAGE:vm:&/;s/$/&:vbd_xvda_iops_total ,/}' vm_uuid.tmp
  
  echo "AVERAGE:host:"$host_uuid":iops_total_"$l_sr_uuid8"" >>vm_uuid.tmp
  #添加rrd2cmd 执行脚本:监控本地磁盘的IO和所有运行的VM IO
  rrd2_cmd=`cat vm_uuid.tmp`
  echo $rrd2_cmd |sed 's/, /,/g' |sed 's/^/rrd2csv /' >rrd2csv.sh
  sed -i '1i #!/bin/sh' rrd2csv.sh
  chmod 777 rrd2csv.sh
  sleep 1
  . ./rrd2csv.sh >xen_iops_"$log".csv & >/dev/null
  rrd2csv_pid=$!  
}


monitor_time(){
while :
do
    read -p "Please input a monitor time:[ exp> 60s or 5m or 1h or 1d ] " time
    # 
    if [ `echo "${time:0:${#time}-1}" |grep -c '[^0-9]'` -ne 0 ] || [ `echo "${time:0-1}" |grep -c '[smhd]'` -ne 1 ]; then
        echo "Input monitor time error!!!"
        continue
    else
        if [ "${time:0:${#time}-1}" -gt 0 ]; then
            break
        else
            echo "Input monitor time error!!!"
            continue
        fi
    fi
done
}

#main
echo "This script for get Local Storage and running VM IOPS ......"
monitor_time
rrd2cmd
echo "Monitor start ... Please wait $time "
sleep $time
sleep 1
kill -9 $rrd2csv_pid >/dev/null 2>&1
sleep 2
echo "Monitor end"
mkdir -p /tmp/xen_iops_"$log"
mv rrd2csv.sh xen_iops_"$log".csv /tmp/xen_iops_"$log" 
rm -rf vm_uuid.tmp
#!/bin/sh
#this script for get xenserver 6.5 7.0 VM storage I/O
#2016/12/21 hayden

#use tool rrd2csv 
#rrd2csv AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_read ,AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_write ,AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_total
#rrd2csv AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_total

log=`date "+%H_%M_%S"`

get_host_uuid(){

host_uuid=`xe host-list |grep uuid |awk -F\: '{print $2}' |sed 's/ //g'`
sleep 1

}

get_vm_info(){

xe vm-list power-state=running |grep -A1 uuid >vm_uuid.tmp
}

get_vm_uuid(){

while :
do
    cat vm_uuid.tmp
  echo "-----------------------------------------------"
  read -p "Please paste VM UUID here:[ exp> xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ] " vm_uuid
    # 
    if [ `cat vm_uuid.tmp |grep -c "$vm_uuid\>"` -ne 1 ];then
    echo "This VM UUID not found,Please try again!!!"
    continue
  else
    echo "---------------------------------------------"
    break
  fi
done
}


get_vm_iops_avg(){

rrd2csv AVERAGE:vm:"$vm_uuid":vbd_xvda_iops_total >vm_iops_avg_"$log" & >/dev/null
#rrd2csv AVERAGE:host:"$host_uuid":iops_total_"$l_sr_uuid8" >host_sr_iops_avg_"$log" & >/dev/null
#rrd2csv AVERAGE:host:"$host_uuid":cpu_avg >host_cpu_avg_"$log" & >/dev/null
rrd2csv_pid=$!

}

monitor_time(){
while :
do
    read -p "Please input a monitor time:[ exp> 60s or 5m or 1h or 1d ] " time
    # 
    if [ `echo "${time:0:${#time}-1}" |grep -c '[^0-9]'` -ne 0 ] || [ `echo "${time:0-1}" |grep -c '[smhd]'` -ne 1 ]; then
        echo "Input monitor time error!!!"
        continue
    else
        if [ "${time:0:${#time}-1}" -gt 0 ]; then
            break
        else
            echo "Input monitor time error!!!"
            continue
        fi
    fi
done
}

#main
echo "This script for get VM Storage IOPS ......"
get_vm_info
get_vm_uuid
monitor_time
get_vm_iops_avg

echo "Monitor start ... Please wait $time "
sleep $time
sleep 1
kill -9 $rrd2csv_pid >/dev/null 2>&1
sleep 2
cp vm_iops_avg_"$log" iops_temp_"$log"
sed -i '1d' iops_temp_"$log"

cat iops_temp_"$log" |awk -F\, '{print $2}' |sed 's/ //g' | sort -n >temp_"$log"
min_iops_t=`head -n 1 temp_"$log"`
min_iops=`echo "scale=2; $min_iops_t"|bc |awk '{printf "%.2f", $0}'`
max_iops_t=`tail -n 1 temp_"$log"`
max_iops=`echo "scale=2; $max_iops_t"|bc |awk '{printf "%.2f", $0}'`
count_temp=`cat temp_"$log" |wc -l`

sum=0
for i in `cat temp_"$log"`
do
    sum=`echo $sum + $i |bc`
done


avg_iops_t=`echo "scale=4; $sum / $count_temp "|bc |awk '{printf "%.4f", $0}'`
avg_iops=`echo "scale=2; $avg_iops_t"|bc |awk '{printf "%.2f", $0}'`

echo VM["$vm_uuid"] min_iops="$min_iops" |tee vm_iops_"$log"
echo VM["$vm_uuid"] max_iops="$max_iops" |tee -a vm_iops_"$log"
echo VM["$vm_uuid"] avg_iops="$avg_iops" |tee -a vm_iops_"$log"

mkdir -p /tmp/vm_iops_"$log"
mv vm_iops_avg_"$log" vm_iops_"$log" /tmp/vm_iops_"$log" 
rm -rf  iops_temp_"$log" temp_"$log" vm_uuid.tmp 

 

转载于:https://www.cnblogs.com/hayden1106/p/8005703.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值