Getting to Know Your XenServer
I am currently auditing our Citrix XenServer 5.6 Pools. I wanted to be able to easily export some data into Microsoft Excel so I can create some Pivot Tables and analyse the data. Knowing excel well. I knew I needed the data to be delimited so that I could use the ‘Text to Columns” feature.
First I had to define what data I wanted to collect. So I made a list:
- VM Name
- Operating System
- vCPU Count
- Memory Allocated
- How many Interfaces
- VLANs connected to
- Number of disks
- Storage allocated for each disk
Once I created this list I was happy that if I could extract all this data I would have enough to perform the analysis I needed.
I had access a XenServer Hypervisor so I started poking around at the “XE” command. I found that the commands gave me some of the information, but when I wanted it all in one place there wasn’t just one command to find it. There are lots of relationships associated with each command and you had to run one command to get a UUID for the next command.
The commands I used were the following:
- xe vm-list
This gave me a list of VMs with their UUID
- xe vif-list
This gave me a list of interfaces a VM had. You have to use the uuid from the above command and use the “vm-uuid” parameter to narrow the interfaces to just this VM
- xe pif-list
Once you get the list of Interfaces, you then need to take the Network UUID from the above command to get the information about that network. The trick here was the same Network UUID is associated with every host in a pool. So to get information for just the network its best to select one host using the “host-name-label=” parameter.
- xe vbd-list
This command gave me a list of block devices for a specific VM. You use the UUID from the “vm-list” command above
- xe vdi-list
Once you have a list of block devices you can take its UUID and use it the get information about each VDI
In the spirit of sharing, I thought I would share with you the script I created:
#!/bin/bash
#echo "Bash version ${BASH_VERSION}..."
#
#Written by Scott Francis
#Crucial Cloud Hosting - 08/02/2013#Find a HV name-label
hv_name=$(xe host-list params=name-label|grep name-label|cut -c 23-|head -n1)echo “UUID|VM Name|Operating System|vCPU Count|Memory(MB)|Networks|VLANS||Disk1 Size(GB)|Disk1 SR|Disk2 Size(GB)|Disk2 SR|Disk3 Size(GB)|Disk3 SR|Disk4 Size(GB)|Disk4 SR”
#Find all VMs which are not a Control Domain
eval array=($(xe vm-list params=uuid is-control-domain=false|grep “uuid”|cut -c 17-))#Loop through each VM and
for i in “${array[@]}”
do
vm_name=$(xe vm-list params=name-label uuid=$i|grep “name-label”|cut -c 23-)
os_version=$(xe vm-list params=os-version uuid=$i|grep “os-version”|cut -c 29-|cut -d\| -f1)
VCPUs_number=$(xe vm-list params=VCPUs-number uuid=$i|grep “VCPUs-number”|cut -c 25-)
memory=$(xe vm-list params=memory-static-max uuid=$i|grep “memory-static-max”|cut -c 30-)
networks=$(xe vm-list params=networks uuid=$i|grep “networks”|cut -c 21-)#Clear concatenated VLAN Variable for the next loop
concat_vlans=#Loop through the VM interfaces and find the VLAN associated with its Network
eval array2=($(xe vif-list vm-uuid=$i|grep “network-uuid”|cut -c 25-))
for a in “${array2[@]}”
do
vlan_number=$(xe pif-list network-uuid=$a host-name-label=$hv_name params=VLAN|cut -c 17-)
concat_vlans=${concat_vlans}”~”$vlan_number
#echo “|$vlan_number”
done#Clear concatenated Disk Variable for the next loop
concat_disks=#Loop though the VM disks and find SR name and Size allocation
eval array3=($(xe vbd-list vm-uuid=$i type=Disk params=vdi-uuid|grep “vdi-uuid”|cut -c 21-))
for b in “${array3[@]}”
do
disk_size=$(xe vdi-list uuid=$b params=physical-utilisation|grep “physical-utilisation”|cut -c 33-)
disk_size_calc=$(($disk_size/1024/1024/1024))
sr_name=$(xe vdi-list uuid=$b params=sr-name-label|grep “sr-name-label”|cut -c 26-)
disk_size_sr=”$disk_size_calc|$sr_name”
concat_disks=${concat_disks}”|”$disk_size_sr
done#Convert memory to MB
mem_calc=$(($memory/1024/1024))#Print a pipe delimited row for the information
echo “$i|$vm_name|$os_version|$VCPUs_number|$mem_calc|$networks|$concat_vlans|$concat_disks”
done
As you can see its pretty straight forward, It gets the information, formats it correctly and then outputs the results.
All you need to do is copy the results to excel and run the “Text to Columns” feature and use the delimiter “|”.
Thanks!
Hosting Options & Info | VPS | Web Solutions & Services |
---|---|---|
-
Sean Thorntoon
-
Jacques
-
Daniel