VMware Cloud Community
MRSYSVM
Contributor
Contributor
Jump to solution

Modify script to handle multiple VMs on Vcenter or host - IOPS IOstats

Originally from:

http://derek858.blogspot.com/2011/06/powercli-script-to-dump-vm-io-stats.html


This script works fine for a single VM to gather iostats , max IOPS..

I would like a version that will create a CSV for all the VM's on a Vcenter server, and I could not quite get it to work with just 1 file output ( rather than a bunch of them ). Other option would be per HOST server.

I think that it needs to be converted to a function and called for each Active Guest VM.
Then I would like a way to schedule it hourly to start gathering statistics. I hope that WIn 2008 scheduled tasks can do this for me.

Any help appreciated.

Thanks !

========================

# diskio-stats.ps1 vmname  minutesback(max 60 for realtime )

$vms = $args[0]
$time = $args[1]
$metrics = "disk.numberwrite.summation","disk.numberread.summation"
$start = (Get-Date).AddMinutes(-$time)
$report = @()
$stats = Get-Stat -Realtime -Stat $metrics -Entity $vms -Start $start
$interval = $stats[0].IntervalSecs
$date = get-date -format "dd-hh-mm-ss"

$report = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{

  $AvgIOPS = [math]::round((($_.Group | `
    Group-Object -Property Timestamp | `
    %{$_.Group[0].Value + $_.Group[1].Value} | `
    Measure-Object -Average).Average / $interval),2)

  $MaxIOPS = ($_.Group | `
    Group-Object -Property Timestamp | `
    %{$_.Group[0].Value + $_.Group[1].Value} | `
    Measure-Object -maximum).maximum /$interval

  $WriteIOs = ($_.Group | Group-Object -Property Timestamp | `
   %{$_.Group[0].Value} | Measure-Object -sum).sum

  $ReadIOs = ($_.Group | Group-Object -Property Timestamp | `
   %{$_.Group[1].Value} | Measure-Object -sum).sum

  $TotalIOs = ($_.Group | `
    Group-Object -Property Timestamp | `
    %{$_.Group[0].Value + $_.Group[1].Value} | `
    Measure-Object -sum).sum

  $ReadRatio = [math]::round(($readios / $totalios),2)

  $WriteRatio = [math]::round(($writeios / $totalios),2)

New-Object PSObject -Property @{
  VM = $_.values[0]
  AvgIOPS = $Avgiops
  MaxIOPS = $MaxIOPS
  WriteIOs = $writeios
  ReadIOs = $readios
  TotalIOs = $totalios
  ReadRatio = $readratio
  WriteRatio = $writeratio
}
}
$report

$report | Export-Csv "C:\_admin\IOPSMax-report-$date.csv" -NoTypeInformation -UseCulture

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you look at my script in the Get the maximum IOPS post, you'll notice that in that script line #5 gets all the powered on VMs.

If you change line #28 to

$report | Export-Csv "C:\_admin\IOPSMax-report-$date.csv" -NoTypeInformation -UseCulture

the CSV will contain the data for all the VMs.

If you want to limit the VMs, you can easily update line #5 to have a selection of VMs.

For example,

$vms= Get-VMHost -Name MyEsx | Get-VM | where {$_.PowerState -eq "PoweredOn"}

will produce a CSV with only the VMs that run on server MyEsx and that are powered on.


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

If you look at my script in the Get the maximum IOPS post, you'll notice that in that script line #5 gets all the powered on VMs.

If you change line #28 to

$report | Export-Csv "C:\_admin\IOPSMax-report-$date.csv" -NoTypeInformation -UseCulture

the CSV will contain the data for all the VMs.

If you want to limit the VMs, you can easily update line #5 to have a selection of VMs.

For example,

$vms= Get-VMHost -Name MyEsx | Get-VM | where {$_.PowerState -eq "PoweredOn"}

will produce a CSV with only the VMs that run on server MyEsx and that are powered on.


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

0 Kudos
MRSYSVM
Contributor
Contributor
Jump to solution

Thaks, that works great for now.

I will be tweaking this perhaps to gather a few more IO stats, but this is great for a start.

I appreciate your help !

0 Kudos