PowerCLI

 View Only
  • 1.  get-stat

    Posted Feb 24, 2009 03:14 PM

    Is there a way to view available metircs for a particluar instance with get-stat. i know i've seen this somewhere but can't seem to find it again.



  • 2.  RE: get-stat

    Posted Feb 27, 2009 09:24 PM

    Afaik this is not possible to do with the current Get-Stat cmdlet.

    In the Get-Stat2 script I updated some weeks ago (see ) there is a parameter, called -queryinstances, that will return all the instances available for a specific metric for a specific entity.

    With that parameter, and the -querymetrics parameter, you can run a script that lists what you ask (I think).

    Something like this:

    
    $esx = Get-VMHost <ESX-hostame> | Get-View
    
    $report = @()
    
    # Get all available metrics
    
    $metrics = ./Get-Stat2.ps1 -entity $esx -querymetrics
    foreach($metric in $metrics){
      $stat = $metric.Group + "." + $metric.Name + "." + $metric.Rollup
      $instances = ./Get-Stat2.ps1 -entity $esx -stat $stat -queryinstances
      foreach($instance in $instances){
        $row = "" | select EntityName, Metric, Instance
    	$row.EntityName = $esx.Name
    	$row.Metric = $instance.Stat
    	$row.Instance= $instance.Instance
    	$report += $row
      }
    }
    
    # Group on the instances property
    
    $groups = $report | Group-Object -Property Instance
    
    # List instance/metric pairs
    foreach($group in $groups){
      foreach($metric in $group.group){
        Write-Host $group.values[0] $metric.Metric
      }
    }
    
    

    Note that this example is for an ESX server but you can get the list for other supported entities in a similar way.

    The list that is produced looks something like this:



  • 3.  RE: get-stat

    Posted Mar 09, 2009 12:00 PM

    Hi Luc,

    I'm trying to run your script but i'm getting the following error. I've made sure i've got the altest version of get-sata2.ps1

    C:\scripts> $esx = Get-View -Id (Get-VMHost xxxxxxxxxx).Id

    C:\scripts> $mystats = ./Get-Stat2.ps1 -entity $esx -start (Get-Date).AddDays(-3) -finish (Get-Date).AddDays(-2) -stat cpu.usage.average -interval HI4

    Security Warning

    Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run

    C:\scripts\Get-Stat2.ps1?

    Do not run Run once Suspend Help (default is "D"): r

    Exception calling "QueryPerf" with "1" argument(s): "A specified parameter was not correct.

    querySpec.maxSample"

    At C:\scripts\Get-Stat2.ps1:197 char:28

    + $stats = $perfMgr.QueryPerf <<<< ($PQSpec)

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

    + FullyQualifiedErrorId : DotNetMethodException

    Cannot index into a null array.

    At C:\scripts\Get-Stat2.ps1:201 char:11

    + if($stats[ <<<< 0].Value -eq $null) {return $null}

    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException

    + FullyQualifiedErrorId : NullArray

    Cannot index into a null array.

    At C:\scripts\Get-Stat2.ps1:205 char:27

    + for($i = 0; $i -lt $stats[ <<<< 0].SampleInfo.Count; $i ++ ){

    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException

    + FullyQualifiedErrorId : NullArray

    C:\scripts>



  • 4.  RE: get-stat

    Posted Mar 09, 2009 01:06 PM

    Did you use v1.1 or v1.2 of met Get-Stat2.ps1 script ?

    I did an update on 02/03/09 and one of the corrections had to with the -Maxsamples parameter.



  • 5.  RE: get-stat

    Posted Mar 09, 2009 01:17 PM

    I used the latest one from the link you provided in your post

    cheers



  • 6.  RE: get-stat

    Posted Mar 09, 2009 01:23 PM

    Does it say v1.2 in the comment at the top of the script ?



  • 7.  RE: get-stat

    Posted Mar 09, 2009 01:50 PM

    sorry v 1.1 where can i get v 1.2 from? i've tried downlaoding from the get-stat rules page but it comes downa s 1.1



  • 8.  RE: get-stat

    Posted Mar 09, 2009 02:41 PM

    Strange, just tried downloading it without logging in and with several browsers.

    It always gives me the v1.2 script.

    Note that I keep a history in the script it also says v1.1 but a bit further it should say v1.2



  • 9.  RE: get-stat

    Posted Mar 09, 2009 02:59 PM

    ok i've now got v 1.2 but i'm still getting the same error