源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

xenserver虚拟机实时性能查看方法

  • 时间:2021-11-15 16:04 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:xenserver虚拟机实时性能查看方法
登陆服务器,执行脚本/opt/tools/real_time_status.sh:(该脚本的相关数据都是从xentop命令中提取的)
#!/bin/bash
# Program:
#    Real-time Performance
# History:
# 2014/09/29 caishunzhi First release
 
DIR="/opt/tools"
HOSTNAME=`/bin/hostname`
SORT=${1:-4}
NUM=${2:-6}
 
function get_performance()
{
 #cpu
 >/tmp/xentopcpu_
 #/usr/sbin/xentop -i2 -d1 -b -f >/tmp/xentopcpu_
 #CPU=`awk -F'[-r]' '{print $NF}' /tmp/xentopcpu_ |grep -v VBD_WR |awk 'BEGIN{sum=0}{sum+=$2}END{print sum}'`
 
 #traffic and io
 /usr/sbin/xentop -i1 -d1 -b -f |grep -v VBD_WR >/tmp/xentop_1
 TX1=`awk -F'[-r]' '{print $NF}' /tmp/xentop_1 |awk 'BEGIN{sum=0}{sum+=$9}END{print sum}'`
 RX1=`awk -F'[-r]' '{print $NF}' /tmp/xentop_1 |awk 'BEGIN{sum=0}{sum+=$10}END{print sum}'`
 VDB_RD1=`awk -F'[-r]' '{print $NF}' /tmp/xentop_1 |awk 'BEGIN{sum=0}{sum+=$13}END{print sum}'`
 VDB_WR1=`awk -F'[-r]' '{print $NF}' /tmp/xentop_1 |awk 'BEGIN{sum=0}{sum+=$14}END{print sum}'`
 sleep 1
 /usr/sbin/xentop -i1 -d1 -b -f |grep -v VBD_WR >/tmp/xentop_2
 TX2=`awk -F'[-r]' '{print $NF}' /tmp/xentop_2 |awk 'BEGIN{sum=0}{sum+=$9}END{print sum}'`
 RX2=`awk -F'[-r]' '{print $NF}' /tmp/xentop_2 |awk 'BEGIN{sum=0}{sum+=$10}END{print sum}'`
 VDB_RD2=`awk -F'[-r]' '{print $NF}' /tmp/xentop_2 |awk 'BEGIN{sum=0}{sum+=$13}END{print sum}'`
 VDB_WR2=`awk -F'[-r]' '{print $NF}' /tmp/xentop_2 |awk 'BEGIN{sum=0}{sum+=$14}END{print sum}'`
 
 date1=`stat /tmp/xentop_1 |grep Modify |awk '{print $2,$3}'`
 date2=`stat /tmp/xentop_2 |grep Modify |awk '{print $2,$3}'`
 start=`date +%s -d "$date1"`
 end=`date +%s -d "$date2"`
 
 let sleep=end-start
 
 #VM Performance Output
 awk '{print $1}' /tmp/xentop_1 >/tmp/vmname_
 awk -F'[-r]' '{print $NF}' /tmp/xentop_1 >/tmp/xentop_11
 awk -F'[-r]' '{print $NF}' /tmp/xentop_2 >/tmp/xentop_22
 awk -F'[-r]' '{print $NF}' /tmp/xentopcpu_ |sed '1,/NAME/d' |awk '{print $2}' >/tmp/xentop_33
 printf "\n%50s %6s s s %6s %6s\n" NAME CPU 'NETin(KB)' 'NETout(KB)' IOr IOw 
 paste /tmp/vmname_ /tmp/xentop_11 /tmp/xentop_22 /tmp/xentop_33 |awk -v n=$sleep '{printf "%50s %6s d d %6d %6d\n",$1,$NF,($27-$10)/n,($28-$11)/n,($31-$14)/n,($32-$15)/n}' |sort -k"$SORT" -rn |head -"$NUM"
}
 
while true;
do 
 get_performance
done
[root@xen-host01 ~]# sh /opt/tools/real_time_status.sh [img]http://files.jb51.net/file_images/article/201412/real_time_status.jpg[/img] 默认以流出流量(第四列)排序,显示前6名。 如果要以其它列排序,直接在脚本后接列号;如果要显示更多的虚拟机,在列号后接要显示的数量。 如下命令以IO读请求数排序(第五列),显示前10名: [root@xen-host01 ~]# sh /opt/tools/real_time_status.sh 5 10 [img]http://files.jb51.net/file_images/article/201412/real_time_status_2.jpg[/img] 注: 默认没有显示虚拟机的cpu使用率,如果要显示,请编辑脚本,将如下两行的注释(#)去掉,保存退出,再执行脚本即可。 [img]http://files.jb51.net/file_images/article/201412/real_time_status_3.png[/img] xentop官方使用说明: [url=http://support.citrix.com/article/CTX127896]How to Use the XenServer Xentop Utility[/url]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部