VMware Cloud Community
bolsen
Enthusiast
Enthusiast
Jump to solution

Script to find "top 10" VMs consuming disk performance?

We are troubleshooting a storage problem and I'm looking for a better way to find VMs which are consuming disk peformance. If I had a wish list, the script would find the "top 10" VMs with the highest disk throughput and IO within the last 24 hours.

Does such a script exist? Any help would be greatly appreciated.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could try the following one-liner

Get-VM | Select Name, 
	@{N="AverageIO"; 
	  E={($_ | Get-Stat -Stat disk.usage.average -Start (Get-Date).adddays(-1) | Measure-Object -Average -Property Value).Average}} | `
	Sort-Object -Property AverageIO -Descending | Select -First 10

This uses the disk.usage.average metric but you can easily use any of the other disk-related metrics.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

You could try the following one-liner

Get-VM | Select Name, 
	@{N="AverageIO"; 
	  E={($_ | Get-Stat -Stat disk.usage.average -Start (Get-Date).adddays(-1) | Measure-Object -Average -Property Value).Average}} | `
	Sort-Object -Property AverageIO -Descending | Select -First 10

This uses the disk.usage.average metric but you can easily use any of the other disk-related metrics.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
cchesley
Enthusiast
Enthusiast
Jump to solution

You can also try our Capacity Analyzer virtual appliance that will show you throughput, disk latency and queue latency for every host, VM and datastore. It can help you quickly determine where the issue is and how to fix it.

Chris


http://www.vkernel.com

http://www.vkernel.com
bolsen
Enthusiast
Enthusiast
Jump to solution

Thanks for the help, that's what I needed!

If I want to write two scripts, one to show write KBsec and one to show read KBsec, is this how I modify it?

Get-VM | Select Name,

@{N="WriteKBsec"; <----


I'm not sure what this is

E={($_ | Get-Stat -Stat disk.write.average -Start (Get-Date).adddays(-1) | Measure-Object -Average -Property Value).Average}} | `

Sort-Object -Property AverageIO -Descending | Select -First 10

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Your script does not work because disk.write.average isn't a supported stat type for a virtual machine. The next one-liner will give you all the supported stat types for virtual machines:

Get-VM | Where-Object { $_.PowerState -eq "PoweredOn" } | Select-Object -First 1 | Get-StatType | Sort-Object -Unique

If I run this script in my environment I get the next output:

cpu.cpuentitlement.latest
cpu.ready.summation
cpu.usage.average
cpu.usagemhz.average
disk.provisioned.latest
disk.unshared.latest
disk.usage.average
disk.used.latest
mem.consumed.average
mem.mementitlement.latest
mem.overhead.average
mem.swapinRate.average
mem.swapoutRate.average
mem.usage.average
mem.vmmemctl.average
net.usage.average
sys.heartbeat.summation
sys.uptime.latest

So the stat types above are the only ones you can use for virtual machines.

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do it all in one script, but it will not be a one-liner anymore Smiley Sad

Something like this

$report = @()
Get-VM | %{
	$stats = Get-Stat -Entity $_ -Stat disk.usage.average,disk.read.average,disk.write.average -Start (Get-Date).adddays(-1) -ErrorAction SilentlyContinue
	if($stats){
		$statsGrouped = $stats | Group-Object -Property MetricId
		$row = "" | Select Name, UsageAvgKbps, ReadAvgKbps, WriteAvgKbps
		$row.Name = $_.Name
		$row.UsageAvgKbps = ($statsGrouped | where {$_.Name -eq "disk.usage.average"} | %{$_.Group | Measure-Object -Property Value -Average}).Average
		$row.ReadAvgKbps = ($statsGrouped | where {$_.Name -eq "disk.read.average"} | %{$_.Group | Measure-Object -Property Value -Average}).Average
		$row.WriteAvgKbps = ($statsGrouped | where {$_.Name -eq "disk.write.average"} | %{$_.Group | Measure-Object -Property Value -Average}).Average
		$report += $row
	}
}
$report | Sort-Object -Property UsageAvgKbps -Descending | Select -First 10

Note1: on the Get-Stat the script retrieves all three metrics in one call

Note2: the -ErrorAction is there to avoid messages for guests where the statistics are not present

Note3: only if there are entries in the $stats array will the script produce a row in the $report array

Note4: for each of the three metrics the script extracts the corresponding values and calculates the average

Note5: you easily replace the property on the Sort-Object cmdlet to see for example the guests that produced the most writes

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Robert, you might want to check your statistics levels because there are a lot more metrics available for a guest.

cpu.cpuentitlement.latest
cpu.extra.summation
cpu.guaranteed.latest
cpu.ready.summation
cpu.swapwait.summation
cpu.system.summation
cpu.usage.average
cpu.usage.maximum
cpu.usage.minimum
cpu.usagemhz.average
cpu.usagemhz.maximum
cpu.usagemhz.minimum
cpu.used.summation
cpu.wait.summation
disk.busResets.summation
disk.commands.summation
disk.commandsAborted.summation
disk.numberRead.summation
disk.numberWrite.summation
disk.provisioned.latest
disk.read.average
disk.unshared.latest
disk.usage.average
disk.usage.maximum
disk.usage.minimum
disk.used.latest
disk.write.average
mem.active.average
mem.active.maximum
mem.active.minimum
mem.consumed.average
mem.consumed.maximum
mem.consumed.minimum
mem.granted.average
mem.granted.maximum
mem.granted.minimum
mem.mementitlement.latest
mem.overhead.average
mem.overhead.maximum
mem.overhead.minimum
mem.shared.average
mem.shared.maximum
mem.shared.minimum
mem.swapin.average
mem.swapin.maximum
mem.swapin.minimum
mem.swapinRate.average
mem.swapout.average
mem.swapout.maximum
mem.swapout.minimum
mem.swapoutRate.average
mem.swapped.average
mem.swapped.maximum
mem.swapped.minimum
mem.swaptarget.average
mem.swaptarget.maximum
mem.swaptarget.minimum
mem.usage.average
mem.usage.maximum
mem.usage.minimum
mem.vmmemctl.average
mem.vmmemctl.maximum
mem.vmmemctl.minimum
mem.vmmemctltarget.average
mem.vmmemctltarget.maximum
mem.vmmemctltarget.minimum
mem.zero.average
mem.zero.maximum
mem.zero.minimum
net.packetsRx.summation
net.packetsTx.summation
net.received.average
net.transmitted.average
net.usage.average
net.usage.maximum
net.usage.minimum
rescpu.actav1.latest
rescpu.actav15.latest
rescpu.actav5.latest
rescpu.actpk1.latest
rescpu.actpk15.latest
rescpu.actpk5.latest
rescpu.maxLimited1.latest
rescpu.maxLimited15.latest
rescpu.maxLimited5.latest
rescpu.runav1.latest
rescpu.runav15.latest
rescpu.runav5.latest
rescpu.runpk1.latest
rescpu.runpk15.latest
rescpu.runpk5.latest
rescpu.sampleCount.latest
rescpu.samplePeriod.latest
sys.heartbeat.summation
sys.uptime.latest

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Thanks Luc,

I will check what is wrong in my environment.

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos