VMware

This Question is Answered

2 "helpful" answers available (6 pts)
5 Replies Last post: Nov 9, 2009 5:42 AM by rassini  

Script to count VMotions per VM posted: Nov 6, 2009 11:34 AM

Click to view rassini's profile Enthusiast 60 posts since
Nov 19, 2008


Looking for a script that will report how many times a VM has migrated witing a give timeframe. -Start date to End date.

Output it to .csv file.

Main purpose is to check if the same VM9s) are constantly migrating with DRS automatic set.

Yes I could set DRS to "partially automatic" and track it manually but that won't capture the overnight activity.

Thanks.

Re: Script to count VMotions per VM

1. Nov 6, 2009 12:35 PM in response to: rassini
Click to view LucD's profile Champion 2,437 posts since
Oct 31, 2005
Did you already look at the scripts I gave in Monitoring DRS VMotion via Powershell ?

Re: Script to count VMotions per VM

3. Nov 7, 2009 12:17 AM in response to: rassini
Click to view LucD's profile Champion 2,437 posts since
Oct 31, 2005
Yes the name of the guest is in the $_.EntityName property.

Re: Script to count VMotions per VM

4. Nov 7, 2009 2:09 AM in response to: rassini
Click to view LucD's profile Champion 2,437 posts since
Oct 31, 2005
That was a rather old script, this is an optimised version for the latest PowerCLI version.
$days = 5			# Number of days back
$tasknumber = 999	# Windowsize for task collector
$eventnumber = 100	# Windowsize for event collector

$report = @()

$taskMgr = Get-View TaskManager
$eventMgr = Get-View eventManager

$filter = New-Object VMware.Vim.TaskFilterSpec
$filter.Time = New-Object VMware.Vim.TaskFilterSpecByTime
$filter.Time.beginTime = (Get-Date).AddDays(-$days)
$filter.Time.timeType = "startedTime"

$tcollection = Get-View ($taskMgr.CreateCollectorForTasks($filter))

$dummy = $tcollection.RewindCollector
$tasks = $tcollection.ReadNextTasks($tasknumber)

$tasks | Where-Object {$_.DescriptionId -like "Drm*"} | Sort-Object StartTime | % {
	$row = "" | Select vmName, StartTime, State, From, To
	$row.StartTime = $_.StartTime
	$row.vmName = $_.EntityName
	$row.State = $_.State
	$efilter = New-Object VMware.Vim.EventFilterSpec
	$efilter.eventChainId = $_.EventChainId

	$ecollection = Get-View ($eventMgr.CreateCollectorForEvents($efilter))
	$events = $ecollection.ReadNextEvents($eventnumber)
	foreach($event in $events){
		switch($event.GetType()){
			"VMware.Vim.DrsVmMigratedEvent" {
				$row.From = $event.SourceHost.Name
			}
			"VMware.Vim.VmBeingHotMigratedEvent"{
				$row.To = $event.DestHost.Name
			}
		}
	}
	$report += $row
# By default 32 event collectors are allowed. Destroy this event collector.
	$ecollection.DestroyCollector()
}
$report | Export-Csv "C:\DRS-vmotion.csv" -NoTypeInformation -UseCulture
# By default 32 task collectors are allowed. Destroy this task collector.
$tcollection.DestroyCollector()
Attachments:

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities