VMware Cloud Community
DSeaman
Enthusiast
Enthusiast

Get total MB VM read/wrote for given interval

I need a means to query stats from a running VM to get the total number of disk MB (not MB/s) that a VM has written and read for a given time period. I'm able to easily get the number of disk read/write IOs, but that doesn't tell me how many bytes of data have been transferred during the interval.  Ideas?

Derek Seaman
Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

If you take the average read/write per interval and multiply that with the length of the interval, you should get the amount of data read or written to a disk.

For example:

$metric = "disk.read.average","disk.write.average" 
$vm
= Get-VM
$start
= (Get-Date).AddHours(-12) $stats = Get-Stat -Entity $vm -Stat $metric -Start $start $stats | Group-Object -Property {$_.Entity.Name} | Select @{N="VM";E={$_.Values[0]}},     @{N="Start";E={$start}},     @{N="Read KB";E={($_.Group | where{$_.MetricID -eq "disk.read.average"} | Measure-Object -Property Value -Sum).Sum}},     @{N="Write KB";E={($_.Group | where{$_.MetricID -eq "disk.write.average"} | Measure-Object -Property Value -Sum).Sum}}    

This will give the amount (in KB) of data read/written over the last 12 hours for each VM.


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

Reply
0 Kudos
mcowger
Immortal
Immortal

I would note that although Luc's method here of calculating the integral (which is what he's doing) will get you an idea, its NOT sufficiently accurate for billing purposes, if thats your plan.

--Matt VCDX #52 blog.cowger.us
Reply
0 Kudos
LucD
Leadership
Leadership

From the question it wasn't clear that this would be for billing.

Besides the fact that my script uses average values, which are by definition not 100% accurate, do you see any other reason for the inaccuracy ?

Is there any other IO we would need to capture ?


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

Reply
0 Kudos
mcowger
Immortal
Immortal

Thats all - just that averages multiplied over time aren't (generally) considered accurate enough for billing.

Theres nothing wrong with your method per se - its probably the most accurate method available.  If *I* were billed on this method though, i wouldn't be happy Smiley Happy

--Matt VCDX #52 blog.cowger.us
Reply
0 Kudos
LucD
Leadership
Leadership

Ok, got it, thanks for the feedback.


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

Reply
0 Kudos
DSeaman
Enthusiast
Enthusiast

Thanks for the script..will try it out tomorrow! It's not going to be used for billing..just general VM usage stats for a lab project. 

Derek Seaman
Reply
0 Kudos