Login server, execute script/opt/tools/real_time_status.sh: (the script's related data are extracted from the xentop command)
#!/bin/bash
# program:
# Real-time Performance
# History:
# 2014/09/29 Caishunzhi
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 ' $date 1 '
end= ' Date +%s-d ' $date 2 '
Let Sleep=end-start
#VM Performance Output
awk ' {print $} '/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 $} ' >/tmp/xentop_33
printf "\n%50s%6s%12s%12s%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 '%12d%12d%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;
Todo
Get_performance
Done
[Root@xen-host01 ~]# sh/opt/tools/real_time_status.sh
The default is sorted by outgoing traffic (column fourth), displaying the top 6 names.
If you want to sort by a different column, connect the column numbers directly after the script, and if you want to display more virtual machines, then the number of items to display after the column number.
The following commands are sorted by IO read requests (column fifth), displaying the top 10:
[root@xen-host01 ~]# sh/opt/tools/real_time_status.sh 5 10
Note:
Default does not show the virtual machine CPU utilization, if you want to display, please edit the script, the following two lines of comments (#) removed, save exit, and then execute the script.