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
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++
}