VMware Cloud Community
jlaco
Enthusiast
Enthusiast
Jump to solution

Script to list vm io latency and the datastore the vm is on

Hello.  We have a vsphere 5.0 environment and we are experiencing some heavy io latency.  I have been looking for a powercli script that will get the io latency for each vm and get the datastore name it currently resides on.  We access our storage over fiber.  I'm trying to get a good overview of io latency in one nice view in a csv.  I found what might be a good base at https://communities.vmware.com/thread/304827?start=0&tstart=0 but I'm not quite sure how to get the datastore name into the array and I think it is written for nfs storage anyway.  Thanks in advance for any info\advice!

69 Replies
warkaj
Contributor
Contributor
Jump to solution

Is that appended to the end of the script or somewhere in the middle?

--- If you found this or any other answer helpful, please consider the use of the Helpful or Correct buttons to award points.
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, on the line with Get-Stat


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

0 Kudos
jlaco
Enthusiast
Enthusiast
Jump to solution

Hi LucD.  I opened this discussion\question a while ago and appreciate the script you worked out for me.  It has come in handy for sure.  I now have a new requirement that would pretty much be the latency script from this discussion with a twist. 

Here's the background.  We have some new flash that will be installed in our storage next week and we want to be able to have an hour by hour report of the latency per datastore both before and after the flash installation.  I have vcenter collecting the stats at level three and have confirmed that the latency stats are showing in vcenter.

Do you have a script already that would accept a date\time range and then output an hourly average of all datastore read\write latencies?

As usual, thanks a bunch!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That would need another Group-Object, where we group the results per hour.

I have an example in PowerCLI & vSphere statistics – Part 2 – Come together

The part that says "Group-Object -Property {$_.Timestamp.Hour" is where I group the results per hour.

Does that help ?


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

0 Kudos
jlaco
Enthusiast
Enthusiast
Jump to solution

Thanks again LucD.  I'll check it out when I get some time and let you know how it goes.

0 Kudos
Pinball
Enthusiast
Enthusiast
Jump to solution

Morning LucD

Any reason why the script will complete with no error but also no output to the file or the screen even if i remove the "Export"

It goes straight to the prompt again?

Thanks

Johan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

One possibility could be that there is no statistical data available for the entities for the interval you requested.

Do you see data for the entities under the Performance tab for the interval ?


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

0 Kudos
Pinball
Enthusiast
Enthusiast
Jump to solution

Hi Luc

Yes the stats is in the database as i can view them from within the C# client.

No error just a next prompt.

Johan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

For me the next step would be to run the script from within a debugger, and check if the intermediate results are correct.

The debugger that comes with the PowerShell ISE should do the trick.


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

0 Kudos
Sivapb
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Can you let us know where we need to add exactly for '"-ErrorAction SIlentlyContinue" in the code


since i'm also getting same error.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

On the line with the Get-Stat cmdlet

Get-Stat -Entity $entity -Stat $stat -Start $start -ErrorAction SilentlyContinue |


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

0 Kudos
Sivapb
Enthusiast
Enthusiast
Jump to solution

Getting following error

lucd.JPG

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That looks as if the $entity variable doesn't hold a valid object.

does the value you specified in the $vmName return VMs ?

Get-VM $vmName


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

0 Kudos
Sivapb
Enthusiast
Enthusiast
Jump to solution

No. i didn't get any VM.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems to be your problem then.

What value did you assign to the variable $vmName ?

That mask doesn't seem to correspond with any VM name in your environment.


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

0 Kudos
Sivapb
Enthusiast
Enthusiast
Jump to solution

Executing following script

$vmName = "VM*"

$stat = "datastore.totalReadLatency.average","datastore.totalWriteLatency.average",

  "datastore.numberReadAveraged.average","datastore.numberWriteAveraged.average"

$entity = Get-VM -Name $vmName

$start = (Get-Date).AddHours(-1)

$dsTab = @{}

Get-Datastore | Where {$_.Type -eq "VMFS"} | %{

  $key = $_.ExtensionData.Info.Vmfs.Uuid

  if(!$dsTab.ContainsKey($key)){

    $dsTab.Add($key,$_.Name)

  }

  else{

    "Datastore $($_.Name) with UUID $key already in hash table"

  }

}

Get-Stat -Entity $entity -Stat $stat -Start $start -ErrorAction SilentlyContinue |

Group-Object -Property {$_.Entity.Name} | %{

  $vmName = $_.Values[0]

  $VMReadLatency = $_.Group |

    where {$_.MetricId -eq "datastore.totalReadLatency.average"} |

    Measure-Object -Property Value -Average |

    Select -ExpandProperty Average

  $VMWriteLatency = $_.Group |

    where {$_.MetricId -eq "datastore.totalWriteLatency.average"} |

    Measure-Object -Property Value -Average |

    Select -ExpandProperty Average

  $VMReadIOPSAverage = $_.Group |

    where {$_.MetricId -eq "datastore.numberReadAveraged.average"} |

    Measure-Object -Property Value -Average |

    Select -ExpandProperty Average

  $VMWriteIOPSAverage = $_.Group |

    where {$_.MetricId -eq "datastore.numberWriteAveraged.average"} |

    Measure-Object -Property Value -Average |

    Select -ExpandProperty Average

  $_.Group | Group-Object -Property Instance | %{

    New-Object PSObject -Property @{

      VM = $vmName

      Host = $_.Group[0].Entity.Host.Name

      Datastore = $dsTab[$($_.Values[0])]

      Start = $start

      DSReadLatencyAvg = [math]::Round(($_.Group |

          where {$_.MetricId -eq "datastore.totalReadLatency.average"} |

          Measure-Object -Property Value -Average |

          Select -ExpandProperty Average),2)

      DSWriteLatencyAvg = [math]::Round(($_.Group |

          where {$_.MetricId -eq "datastore.totalWriteLatency.average"} |

          Measure-Object -Property Value -Average |

          Select -ExpandProperty Average),2)

      VMReadLatencyAvg = [math]::Round($VMReadLatency,2)

      VMWriteLatencyAvg = [math]::Round($VMWriteLatency,2)

      VMReadIOPSAvg = [math]::Round($VMReadIOPSAverage,2)

      VMWriteIOPSAvg = [math]::Round($VMWriteIOPSAverage,2)

    }

  }

} | Export-Csv c:\report.csv -NoTypeInformation -UseCulture

Getting error message only. no output

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you have any VMs whose name starts with the letters "VM" ?

You will have to update the name mask. For example, if the VMs for which you want run the report start with "FIN", then you do

$vmName = "FIN*"

If you want the report for all VMsin your environment you could do

$vmName = "*"

How do you want to select the VMs for which the report needs to run ?


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

0 Kudos
Sivapb
Enthusiast
Enthusiast
Jump to solution

I want report for all VMs. Changed the value $vmName = "*" and executed it took long time. but the out put is empty file

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Objects you place on the pipeline inside a foreach construct are not passed to the pipeline outside the foreach construct.

Use the call operator (&) as a bypass.

See attached script


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

0 Kudos
Sivapb
Enthusiast
Enthusiast
Jump to solution

Thanks lot LucD. Perfectly working.

If i need last 1 month or 20 days . which line to be modify in that CLI?

0 Kudos