Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 206069

Re: Problem with get-stat command and scripting

$
0
0

Try something like this

 

$midnight=Get-Date-Hour0-Minute0-Second0
$metrics_rp="cpu.usagemhz.average","cpu.usagemhz.maximum"
$rp=Get-Cluster-Namecluster1,cluster2|Get-ResourcePool

Get-Stat-Entity$rp-Stat$metrics_rp-Start$midnight.adddays(-1).addminutes(-1) -Finish$midnight.addminutes(-1) |
Group-Object-Property {$_.EntityId} |%{
 
$cluster=   &{
   
$parent=$_.Group[0].Entity.Parent
   
while ($parent-and  $parent.ExtensionData-isnot [VMware.Vim.ClusterComputeResource]){
     
$parent=$parent.Parent
    }
   
$parent
  }
 
$report=@()
 
$_.Group|Group-Object-Property {$_.Timestamp.Hour} |%{
   
$row=""|Select"Interval Start","Resource Pool",Cluster,"CPU MHz Avg","CPU MHz Max"
   
$row."Interval Start"=$_.Group|Sort-Object-PropertyTimestamp|
     
Select-First1|Select-ExpandPropertyTimestamp
   
$row.Cluster=$cluster.Name
   
$row."Resource Pool"=$_.Group[0].Entity.Name
   
$row."CPU MHz Avg"=$_.Group|Where {$_.MetricId-eq"cpu.usagemhz.average"} |
     
Measure-Object-PropertyValue-Average|Select-ExpandPropertyAverage
   
$row."CPU MHz Max"=$_.Group|Where {$_.MetricId-eq"cpu.usagemhz.maximum"} |
     
Measure-Object-PropertyValue-Maximum|Select-ExpandPropertyMaximum
   
$report+=$row
  }
 
$report|Export-CsvC:\stats\$($cluster.Name)-$($_.Group[0].Entity.Name)_stats.csv
}

Viewing all articles
Browse latest Browse all 206069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>