查看运行在XenServer下的所有VM名称、UUID以及dom-id

在XenServer中,使用sar -n DEV 1 1命令查看各VM的网络状态,内含的vif{数字},实际为dom-id.

比如:

Average:        IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
Average:           lo     35.00     35.00   8532.00   8532.00      0.00      0.00      0.00
Average:         eth0    164.00    161.00 116555.00  70966.00      0.00      0.00      1.00
Average:         eth1      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:       xenbr0     18.00     16.00   1989.00   7922.00      0.00      0.00      3.00
Average:      vif33.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:     vif130.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:     vif599.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif1314.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif1391.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif1718.0      2.00      4.00    104.00    246.00      0.00      0.00      0.00
Average:    vif2028.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif2182.0      5.00      8.00   4740.00    695.00      0.00      0.00      0.00
Average:    vif2838.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif2967.0      2.00      5.00    810.00    300.00      0.00      0.00      0.00
Average:    vif3085.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3177.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3211.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3212.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3215.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3216.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3218.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3221.1      4.00      8.00   1122.00    775.00      0.00      0.00      0.00
Average:    vif3223.1    110.00    123.00  51135.00 112317.00      0.00      0.00      0.00
Average:    vif3231.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3233.1     14.00     13.00   1028.00    879.00      0.00      0.00      0.00
Average:    vif3298.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3404.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3417.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3429.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3465.0      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3529.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3564.1      5.00      6.00   1943.00    362.00      0.00      0.00      0.00
Average:    vif3614.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00
Average:    vif3615.1      0.00      3.00      0.00    180.00      0.00      0.00      0.00

但是该id不能直接取得,在维护中,非常麻烦,所以写了个小脚本,来减轻重复工作,下面是运行结果:

[root@PDS1339 ~]# sh show*
vps2040 is running on dom-id is 3404 on UUID is 314d1aa5-afee-xxxx-xxxx-2f45e2f4a139
vps2071 is running on dom-id is 3218 on UUID is 004939a5-f175-031d-xxxx-aa1e7ea03ae4
vps3009 is running on dom-id is 3223 on UUID is ae2aadad-143a-169e-xxxx-ef4a275466d6
vps4408 is running on dom-id is 3298 on UUID is 14a846aa-44fa-eaa2-xxxx-9ad07981a942
vps2048 is running on dom-id is 130 on UUID is ae89ae50-0ea2-44a5-xxxx-aeae3d3aa445
vps4490 is running on dom-id is 3564 on UUID is da948d3e-3afe-4e0f-xxxx-108f95122945
vps4258 is running on dom-id is 3231 on UUID is ee006286-7e92-da17-xxxx-f78a7a2af9a1
vps2533 is running on dom-id is 3085 on UUID is 0df511a9-3fa2-f9a9-xxxx-9e2ea0a30a34
vps4449 is running on dom-id is 3429 on UUID is a064f428-79a6-5e9f-xxxx-1d84806a6767
vps2104 is running on dom-id is 3221 on UUID is eea6e087-328a-a9f5-xxxx-1ed119a578a0
Control is running on dom-id is 0 on UUID is ed6592a9-a39e-4995-xxxx-23611967af55
vps3033 is running on dom-id is 1718 on UUID is 84aef63a-3866-3788-xxxx-83d7187e0369
vps4304 is running on dom-id is 3211 on UUID is 95700860-9333-df4e-xxxx-ae430706013a
vps3156 is running on dom-id is 1314 on UUID is a3d5a793-13a1-ef59-xxxx-072a2f93f450
vps2092 is running on dom-id is 2182 on UUID is 7a040aaf-28d3-2470-xxxx-347600088186
vps3885 is running on dom-id is 3465 on UUID is a4803752-688a-88f2-xxxx-722a2faafda7
vps2014 is running on dom-id is 33 on UUID is da51231a-ad96-ae6d-xxxx-557f981d70a8
vps2398 is running on dom-id is 599 on UUID is a64a5d76-3d76-aa95-xxxx-3aa28af33a60
vps3935 is running on dom-id is 3615 on UUID is fdf83af0-fae0-846e-xxxx-87daee7a51ef
vps2079 is running on dom-id is 3177 on UUID is 087e934a-a28a-ff9d-xxxx-12f13f6adee2
vps3934 is running on dom-id is 3614 on UUID is 12a30328-87ae-9e07-xxxx-14e4a6d8a399
vps3384 is running on dom-id is 3529 on UUID is 0fa089ea-9145-6a83-xxxx-6da1160ae1d2
vps4392 is running on dom-id is 3233 on UUID is daa6a8f0-839f-387e-xxxx-72fa88ea97ee
vps4286 is running on dom-id is 3215 on UUID is 51a70a32-534a-655a-xxxx-9859366953e9
vps2612 is running on dom-id is 3417 on UUID is 9de114fa-17a0-3fa7-xxxx-e77a5a06d977
vps4088 is running on dom-id is 2838 on UUID is 306aa2a0-f0e0-2326-xxxx-a0ddaadaa9a8
vps3409 is running on dom-id is 1391 on UUID is ae2f6a39-e09a-a94d-xxxx-8916a6f091d7
vps2046 is running on dom-id is 2967 on UUID is 2f8e0f76-8ff3-5ae0-xxxx-afe2a1fa2a66
vps4256 is running on dom-id is 3216 on UUID is 71eaf09d-658d-aa5a-xxxx-0aa1e61d567a
vps2030 is running on dom-id is 2028 on UUID is 83aa63f3-f078-38ea-xxxx-15fade9faffa
vps4305 is running on dom-id is 3212 on UUID is aa1a223a-1ea2-48a7-xxxx-6a314a4aa973

附脚本内容:

#!/bin/bash
for UUID in $(xe vm-list power-state=running --minimal | tr -s "," "\n" ); do
eval $(xe vm-list uuid="${UUID}" params=name-label,dom-id |awk 'NR==1{print "NAME="$5}NR==2{print "DOMID="$4}')
echo "${NAME} is running on dom-id is ${DOMID} on UUID is ${UUID}"
done

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据