Hi,
I am unable to get the performance details for a VM as getting the below error
$servers=Get-Content ".\servers.txt"
foreach ($server in $servers)
{
$vm=Get-VM $server
if($? -eq $false)
{
continue
}
$fileName=".\$server.csv"
$diskusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-1) -IntervalMins 60 -stat "disk.usage.average" | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp
$memusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-1) -IntervalMins 60 -stat "mem.usage.average" | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp
$cpuusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-1) -IntervalMins 60 -stat "cpu.usage.average" | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp
$netusageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).AddDays(-1) -IntervalMins 60 -stat "net.usage.average" | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp
Set-Content -Value "ServerName,AVG_CPU_Time,AVG_CPU,AVG_MEM,AVG_disk,AVG_Net" -Path $fileName
$diskus=0
for ($i=0;$i -lt $cpuusageaverage.Count ; $i++)
{
if (($diskus -lt $diskusageaverage.count) -and ($cpuusageaverage[$i].Timestamp -eq $diskusageaverage[$diskus].Timestamp))
{
Add-Content -Value "$($cpuusageaverage[$i].Entity.Name),$($cpuusageaverage[$i].Timestamp),$($cpuusageaverage[$i].Value),$($memusageaverage[$i].Value),$($diskusageaverage[$diskus].Value),$($netusageaverage[$i].value)" -Path $fileName
$diskus++
}
else
{
Add-Content -Value "$($cpuusageaverage[$i].Entity.Name),$($cpuusageaverage[$i].Timestamp),$($cpuusageaverage[$i].Value),$($memusageaverage[$i].Value),0,$($netusageaverage[$i].value)" -Path $fileName
}
}
}
return(0)
Error:
| Get-Stat : 12-08-2019 12:17:24 Get-Stat | The metric counter "disk.usage.average" doesn't exist for entity |
At D:\perf\3.ps1:10 char:23
+ ... sageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).Ad ...
| + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| + CategoryInfo | : ResourceUnavailable: (disk.usage.average:String) [Get-Stat], VimException |
| + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation. |
ViCore.Cmdlets.Commands.GetViStats
| Get-Stat : 12-08-2019 12:17:25 Get-Stat | The metric counter "mem.usage.average" doesn't exist for entity |
At D:\perf\3.ps1:11 char:22
+ ... sageaverage=Get-Stat -entity $vm -MaxSamples 168 -Start (Get-Date).Ad ...
| + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| + CategoryInfo | : ResourceUnavailable: (mem.usage.average:String) [Get-Stat], VimException |
| + FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation. |
ViCore.Cmdlets.Commands.GetViStats