Tag Archives: Xenserver

Xenserver stat script

This powershell script will give you number of virtual machines running on each xenserver in each xen server pool, it will also give you total amount of memory in each server and how much is free. For each poolmaster it will also give you the numer of stopped Vm’s.

Import-Module ‘C:\Program Files (x86)\Citrix\XenServerPSSnapIn\XenServerPSSnapIn.dll’
# Specify each pool master in the $XenServer array.
$XenServers =@(“srv-xen-0001″,”srv-xen-100″,”srv-xen-300”)
$date=Get-Date -format “yyMMd”
$file = “\c:\temp\Xen\XENStats_$date.csv”

function SendMail
{
# Send-MailMessage -To “someone@mail.com” -Subject “XEN Server Statistics” -From “xenserver@local” -Body “See attachment for the report” -SmtpServer “mail.local” -Attachments $file
}

function GetXenStats
{
“Hostname,VMs,MemTotal,MemFree”
foreach ($XenServer in $XenServers)
{
### Create connection to the PoolMaster
$connect=Connect-XenServer -Server $XenServer -UserName root -Password xenserver -NoWarnCertificates -NoWarnNewCertificates
### Ask the poolmaster which XenServers belongs to that pool
$XenHosts=Get-XenServer:Host -Server $XenServer

$HaltedVMs = Get-XenServer:VM -Server $XenServer| Where { $_.power_state -eq “Halted” -and $_.is_a_template -ne “True”}|fl name_label
$Halted = $HaltedVMs.Count

“$XenServer,$Halted”

foreach ($XenHost in $XenHosts)
{
$hostname = $XenHost.hostname
$VMs = Get-XenServer:Host.ResidentVMs -Server $XenServer -Host $hostname
$VM_on_host = $VMs.Count – 1

# -Server is the poolmaster and -Host is the Xen-host to query
$metrics = Get-XenServer:Host.Metrics -Server $XenServer -Host $hostname
$mem_free = $metrics.memory_free
$mem_total = $metrics.memory_total

“$hostname,$VM_on_host,$mem_total,$mem_free”
}
$temp=Disconnect-XenServer -Server $XenServer
$XenHosts = “”
}
}

########## Main Program ###########

$output=GetXenStats
$output|out-file $file
#SendMail

Advertisements