Automation

 View Only
Expand all | Collapse all

Get-Stat script help

  • 1.  Get-Stat script help

    Posted Mar 20, 2009 03:42 PM

    Hi

    I'm running the following script which used to work, but since i've upgraded to the latest version of the toolkit 1.5 142961 i get the following error:

    Get-Stat : 20/03/2009 13:54:58 Get-Stat The metric counter "clusterservices.cpufairness.latest" doesn't exist for entity "svr-vm

    At C:\scripts\Host-Stats.ps1:55 char:20

    + $Stats = Get-Stat <<<< -Entity $ESX -Start $Start -Finish $Finish -stat $Stat -IntervalSecs 300 -MaxSamples 1000

    + CategoryInfo : ResourceUnavailable: (:smileyhappy: , VimException

    + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.Commands.GetViStats

    Strange thing is the script does actually run and collect data but just throws the error. the first time it tries to collect a data point from a host and only then. I think I was running a previous version of 1.5 toolkit before I upgraded don't know what build though. Here's my script..

    (Following Function copied from LUCD's get-stat.ps1 script)

    Function QueryPerf($entity)

    {

    $perfMgr = Get-View (Get-View ServiceInstance).content.perfManager

    1. Create performance counter hashtable

    $pcTable = New-Object Hashtable

    $keyTable = New-Object Hashtable

    foreach($pC in $perfMgr.PerfCounter){

    if($pC.Level -ne 99){

    $pctable.Add(($pC.GroupInfo.Key + "." + $pC.NameInfo.Key + "." + $pC.RollupType),$pC.Key)

    $keyTable.Add($pC.Key, $pC)

    }

    }

    $metrics = $perfMgr.QueryAvailablePerfMetric($entity.MoRef,$null,$null,$numinterval)

    $metricslist = @()

    foreach($pmId in $metrics){

    $row = "" | select Group, Name, Rollup

    $pC = $keyTable[http://$pmId.CounterId|http://$pmId.CounterId]

    $row.Group = $pC.GroupInfo.Key

    $row.Name = $pC.NameInfo.Key

    $row.Rollup = $pC.RollupType

    $metricslist += $row

    }

    return ($metricslist | Sort-Object -unique -property Group,Name,Rollup)

    }

    Connect-VIServer svr-vmc-crs01

    $entity = get-view -id (Get-VMHost svr-vmh-crcla01.lbcamden.net).id

    $arrPerfcounters = QueryPerf($entity)

    $xl = New-Object -comobject Excel.Application

    $xl.Visible = $true

    $xl.sheetsInNewWorkbook = $arrPerfcounters.length

    $wb = $xl.Workbooks.add()

    $Start = (Get-Date).adddays(-1)

    $Finish = (Get-Date)

    $PerfCounterWorkSheet = 1

    Foreach ($PC in $arrPerfCounters){

    $ws = $wb.Worksheets.Item($PerfCounterWorkSheet)

    $ws.name = $PC.Group + "." + $PC.Name

    $HostCount = 1

    $AllESXHosts = Get-cluster cressy | Get-VMHost

    foreach ($ESX in $AllESXHosts){

    $StatCount = 2

    $ws.Cells.Item(1,$HostCount+1) = "$ESX"

    $stat = $PC.Group + "." + $PC.Name + "." + $PC.Rollup

    $Stats = Get-Stat -Entity $ESX -Start $Start -Finish $Finish -stat $Stat -IntervalSecs 300 -MaxSamples 1000

    foreach ($stat in $stats){

    $ws.cells.item($statCount,1) = $stat.timestamp

    $ws.Cells.Item($StatCount,$HostCount+1) = $stat.Value

    $StatCount++

    }

    $HostCount++

    }

    $PerfCounterWorkSheet++

    }



  • 2.  RE: Get-Stat script help

    Posted Mar 20, 2009 07:06 PM

    I reported a similar problem with the cpu.reservedCapacity.average metric.

    One of the developers, Yavor, confirmed that he could reproduce the problem and he has logged a bug.

    @Yavor, is this a similar problem ?



  • 3.  RE: Get-Stat script help

    Posted Mar 21, 2009 08:28 AM

    i get the error for all available metrics when running the script.



  • 4.  RE: Get-Stat script help

    Posted Mar 22, 2009 01:25 PM

    I extended your script a bit and ran it for all types of accepted entities an for all available intervals.

    There are indeed quit a lot of metrics for which the error message is returned but not all of them.

    See the attached CSV.

    The "Interval" column shows the interval in seconds.

    The "Error" column says if the error message was shown and the "Data" column says if the Get-Stat actually returned some data.

    Note that there are some metrics that show that no data was returned but I'm busy investigating that further.

    I suspect this is related to the "level" one defines for a specific interval.



  • 5.  RE: Get-Stat script help

    Posted Jun 12, 2009 11:29 PM

    Hi LucD

    How would I adjust the above script to just run against a specific stat (such as disk or cpu?) Also, I noticed your get-stat2 script is no longer posted?



  • 6.  RE: Get-Stat script help

    Posted Jun 12, 2009 11:46 PM

    Yes, I know.

    That document was in a funny state (somewhere between draft and published), when I removed the draft everything was gone.

    In the mean time I got a backup from Robert (thanks for that).

    I will post the article and the script again somewhere this weekend.

    With the Get-Stat cmdlet you can ask for specific metrics through the -Stat parameter.

    Something like

    Get-Stat -Stat cpu.usage.average ....
    

    Is that what you meant ?



  • 7.  RE: Get-Stat script help

    Posted Jun 13, 2009 12:49 AM

    I was more referring to the code below posted by houghtp, that uses the QueryPerf function. I wanted to adjust it to just output and create a spreadsheet for specidic stat categories.(such as all disk stats, all cpu stats)

    (Following Function copied from LUCD's get-stat.ps1 script)

    Function QueryPerf($entity)

    {

    $perfMgr = Get-View (Get-View ServiceInstance).content.perfManager

    1. Create performance counter hashtable

    $pcTable = New-Object Hashtable

    $keyTable = New-Object Hashtable

    foreach($pC in $perfMgr.PerfCounter){

    if($pC.Level -ne 99){

    $pctable.Add(($pC.GroupInfo.Key + "." + $pC.NameInfo.Key + "." + $pC.RollupType),$pC.Key)

    $keyTable.Add($pC.Key, $pC)

    }

    }

    $metrics = $perfMgr.QueryAvailablePerfMetric($entity.MoRef,$null,$null,$numinterval)

    $metricslist = @()

    foreach($pmId in $metrics){

    $row = "" | select Group, Name, Rollup

    $pC = $keyTable[http://$pmId.CounterId|http://$pmId.CounterId]<http://$pmId.CounterId>

    $row.Group = $pC.GroupInfo.Key

    $row.Name = $pC.NameInfo.Key

    $row.Rollup = $pC.RollupType

    $metricslist += $row

    }

    return ($metricslist | Sort-Object -unique -property Group,Name,Rollup)

    }

    Connect-VIServer vcserver

    $entity = get-view -id (Get-VMHost anyhost).id

    $arrPerfcounters = QueryPerf($entity)

    $xl = New-Object -comobject Excel.Application

    $xl.Visible = $true

    $xl.sheetsInNewWorkbook = $arrPerfcounters.length

    $wb = $xl.Workbooks.add()

    $Start = (Get-Date).adddays(-1)

    $Finish = (Get-Date)

    $PerfCounterWorkSheet = 1

    Foreach ($PC in $arrPerfCounters){

    $ws = $wb.Worksheets.Item($PerfCounterWorkSheet)

    $ws.name = $PC.Group + "." + $PC.Name

    $HostCount = 1

    $AllESXHosts = Get-cluster Clust01 | Get-VMHost

    foreach ($ESX in $AllESXHosts){

    $StatCount = 2

    $ws.Cells.Item(1,$HostCount+1) = "$ESX"

    $stat = $PC.Group + "." + $PC.Name + "." + $PC.Rollup

    $Stats = Get-Stat -Entity $ESX -Start $Start -Finish $Finish -stat $Stat -IntervalSecs 300 -MaxSamples 1000

    foreach ($stat in $stats){

    $ws.cells.item($statCount,1) = $stat.timestamp

    $ws.Cells.Item($StatCount,$HostCount+1) = $stat.Value

    $StatCount++

    }

    $HostCount++

    }

    $PerfCounterWorkSheet++

    }



  • 8.  RE: Get-Stat script help

    Posted Jun 15, 2009 08:44 AM

    Yes it seems like the same problem! I'll post some more details about it later on this week!

    10x,

    Yavor



  • 9.  RE: Get-Stat script help

    Posted Nov 20, 2009 09:23 AM

    Hi Luc, all,

    The problem that was causing errors to be thrown for some of the metrics was addressed in the newly released version of PowerCLI - 4.0 Update 1. Give it a try and I'll be happy to get further feedback in case you still experience some problems in the specified cases!

    \Yavor



  • 10.  RE: Get-Stat script help

    Posted Nov 20, 2009 09:32 AM

    Thanks Yavor, will try them out asap.



  • 11.  RE: Get-Stat script help

    Posted Jun 17, 2009 12:56 PM

    Luc, Paul,

    We've found the problem causing first an error to be thrown then to list the available statistics for the specified performance counter and it will be fixed for one of the upcoming releases. With the current behavior the listed statistics are the correct ones regardless the thrown error. I'm talking about the cases where both errors and statistics are printed. By the way the error can be hidden if you set $erroractionpreference = "SilentlyContinue". Now looking at Luc's csv table the cases where only error is thrown and no statistics are retrieved by my opinion are cases where actually there are no statistics available on the server and the error is correct.

    Your feedback is highly appreciated!

    \Yavor



  • 12.  RE: Get-Stat script help

    Posted Jun 17, 2009 01:28 PM

    Yavor,

    Thanks for the feedback.

    Your remark about the error message being displayed and no data being being displayed is correct.

    That probably is also related to the statistics level as well.

    Having a level 4 statistics for all periods is most probably too much data :smileywink:

    Looking forward to the next build.