VMware Cloud Community
np123
Enthusiast
Enthusiast

disk I/O per vmdk

I’m using powercli to report vms with heavier and lighter disk I/O. The report helps us keep our most active virtual disks on our faster datastores. So far I’ve been using get-stat to report disk.usage.average. This approach works well for vms whose virtual disks are all on the same datastore:

get-vm -datastore <datastoreName> |

                                Select `

                                                Name, `

                                                @{N="kbps";E={[Math]::Round((($_ | Get-Stat -Stat disk.usage.average -Start (Get-Date).addmonths(-1) | Measure-Object Value -Average).Average),2)}}, ` |

sort "kbps" | format-table –autosize

But some of our vms have virtual disks on multiple datastores. The above approach seems to aggregate a vm's usage across datastores, and I don't want to do that. Not surprisingly, in other words, for <sampleVm> with virtual disks on datastores 258078 and 159896:

this...

get-vm <sampleVm> -datastore (get-datastore -id Datastore-datastore-258078) | get-stat -stat disk.usage.average | measure value -average

…returns the same value as this

get-vm <sampleVm> -datastore (get-datastore -id Datastore-datastore-159896) | get-stat -stat disk.usage.average | measure value -average

So for the vms with virtual disks on multiple datastores, I’d like to pull disk I/O separately for each vmdk. Any suggestions? Thanks in advance for having a look.

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership

Try the virtualdisk.read.average and the virtualdisk.write.average metrics.

The instances are the vdisks of a VM.


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

Reply
0 Kudos
np123
Enthusiast
Enthusiast

Thanks. Do you mean disk.read.average and disk.write.average? Or virtualdisk.read.average and virtualdisk.write.average are different? If there's anything available within vc stat level 1, that would be ideal. If not, sounds like we may need stat level 3 for this. Apparently disk.read and disk.write require level 3: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/disk.html

Reply
0 Kudos
LucD
Leadership
Leadership

No, I do mean virtualdisk.read.average and virtualdisk.write.average.

According to the PerformanceManager entry for Virtual Disk these metrics require level 2.


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

np123
Enthusiast
Enthusiast

We may not be able to change the stat level anytime soon. When we do, I'll know where to start. I appreciate the help.

Reply
0 Kudos
LucD
Leadership
Leadership

A short example script that will get you the read and write average values per vdisk over the last 4 hours

$metrics = "virtualdisk.read.average","virtualdisk.write.average" 
$vm = Get-VM MyVM
$start
= (Get-Date).AddHours(-4) $controllerTab = @{} $vm | Get-ScsiController | %{     $controllerTab.Add($_.ExtensionData.BusNumber,$_.Name) }

$diskTab = @{} $vm | Get-HardDisk | %{     $diskTab.Add($_.UnitNumber,$_.Name) }
$stats
= Get-Stat -Entity $vm -Stat $metrics -Start $start
$stats | Group-Object -Property Instance | %{     New-Object PSObject -Property @{         VM = $_.Group[0].Entity.Name         Controller = $controllerTab[[int]($_.Name.Split(':')[0].TrimStart('scsi'))]         Disk = $diskTab[[int]($_.Name.Split(':')[1])]         AvgRead = ($_.Group | where {$_.MetricId -eq "virtualdisk.read.average"} | Measure-Object -Property Value -Average).Average         AvgWrite = ($_.Group | where {$_.MetricId -eq "virtualdisk.write.average"} | Measure-Object -Property Value -Average).Average     } }


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

Reply
0 Kudos
bvi1006
Enthusiast
Enthusiast

Hi Luc,

I could really use this script right now Smiley Happy ... .

However, I'm getting the errors:

Exception calling "Add" with "2" argument(s): "Key cannot be null.

Parameter name: key"

.ps1:11 char:17

+ $diskTab.Add <<<< ($_.UnitNumber,$_.Name)

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

Exception calling "Add" with "2" argument(s): "Key cannot be null.

Parameter name: key"

At C.ps1:11 char:17

+ $diskTab.Add <<<< ($_.UnitNumber,$_.Name)

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

Get-Stat : A positional parameter cannot be found that accepts argument '$null'.

At .ps1:13 char:18

+ $stats = Get-Stat <<<< -Entity $vm -Stat $metrics -Start $start $stats | Group-Object -Property Instance | %{

+ CategoryInfo : InvalidArgument: (:) [Get-Stat], ParameterBindingException

+ FullyQualifiedErrorId : PositionalParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

Any ideas?
Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

The Get-Stat error was because of a missing Cr-LF in that line. I corrected that in the code above.

The Add error is strange.

That would mean you have a harddisk with no unitnumber, or a harddisk object that doesn't have the UnitNumber property.

Which PowerCLI version are you running ?

Get-PowerCLIVersion


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

Reply
0 Kudos
bvi1006
Enthusiast
Enthusiast

I'm using

VMWare vSphere PowerCLI 4.1 U1 build 332441...

Still having trouble with the script, any chance you could attach it instead of me trying to copy?

Thanks Luc

Reply
0 Kudos
LucD
Leadership
Leadership

Sure, file attached.

That PowerCLI version would explain the Unitnumber absence.

Can you upgrade to 5.1 ?


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

Reply
0 Kudos
AlbertWT
Virtuoso
Virtuoso

Thanks for sharing the script Luc,

do I have to use vSPhere 5.1 to use PowerCLI 5.1 Update 1 ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership

No, have a look at the PowerCLI 5.1 Release Notes to learn about the supported vSphere platforms.


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

Reply
0 Kudos
bvi1006
Enthusiast
Enthusiast

Thanks Luc.

I actually ended up using your script posted here:

Using PowerCLI to get VM Disk Stats

http://communities.vmware.com/thread/304827

Even better, thanks Smiley Wink

Reply
0 Kudos