xenserver 虚拟机响应时间对比

#!/bin/sh
#this script for get xenserver 6.5 7.0 VM VBD and Host storage read/write response time
#2016/12/21 hayden
#2016/12/29 

#use tool rrd2csv 
#rrd2csv AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:read_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:write_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:read_latency_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:write_latency_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:io_throughput_read_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:io_throughput_write_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:io_throughput_total_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:iops_read_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:iops_write_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:iops_total_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:iowait_75499043 ,AVERAGE:host:12fa2131-192a-4f7d-a65d-8ff0367019cc:inflight_75499043
#rrd2csv AVERAGE:vm:5495cb3f-1789-d4d3-f413-f2b0e56d135f:vbd_xvda_read_latency ,AVERAGE:vm:5495cb3f-1789-d4d3-f413-f2b0e56d135f:vbd_xvda_write_latency, AVERAGE:vm:5495cb3f-1789-d4d3-f413-f2b0e56d135f:vbd_xvda_iops_read ,AVERAGE:vm:5495cb3f-1789-d4d3-f413-f2b0e56d135f:vbd_xvda_iops_write ,AVERAGE:vm:5495cb3f-1789-d4d3-f413-f2b0e56d135f: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_read_latency ,” 和“:vbd_xvda_wite_latency ,” 关键字  
  sed '/./{s/^/AVERAGE:vm:&/;s/$/&:vbd_xvda_read_latency ,/}' vm_uuid.tmp >vm_uuid.res_t
  sed '/./{s/^/AVERAGE:vm:&/;s/$/&:vbd_xvda_write_latency ,/}' vm_uuid.tmp >>vm_uuid.res_t
  echo "AVERAGE:host:"$host_uuid":read_latency_"$l_sr_uuid8" ," >>vm_uuid.res_t
  echo "AVERAGE:host:"$host_uuid":write_latency_"$l_sr_uuid8"" >>vm_uuid.res_t 
  
  #添加rrd2cmd 执行脚本:监控本地磁盘和所有运行VM 的读写响应时间
  rrd2_cmd=`cat vm_uuid.res_t`
  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_res_t_"$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 Response time ......"
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_res_t_"$log"
mv rrd2csv.sh xen_res_t_"$log".csv /tmp/xen_res_t_"$log" 
rm -rf vm_uuid.tmp vm_uuid.res_t

 

posted @ 2017-12-08 15:47  hayden__wang  阅读(379)  评论(0编辑  收藏  举报