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

Re: Cpu data gathering script - need help optimizing it.

$
0
0

Hello

 

Thank you very much for the suggestions, the single Get-Stat command made a noticeable difference,

The adjusted script is below, there are fixed delays set for individual hosts so the data is gathered every 19-20 seconds, now I see that I misunderstood your suggestion, I will consider remaking it to calculate the time it takes torun a single check and adjust the delay on the fly.

 

If there is a way to make the script less cpu heavy for the host that is probed I would love to hear it

Thanks for helping.

 

$Hosts = @(
"xx.xx.xx.1",
"xx.xx.xx.2",
"xx.xx.xx.3",
"xx.xx.xx.4",
"xx.xx.xx.5",
"xx.xx.xx.6",
"xx.xx.xx.10",
"xx.xx.xx.11",
"xx.xx.xx.12")
$counter = 1500
Foreach ($Server in $Hosts){     Start-Job -ScriptBlock {           param ($Server, $counter)          Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue          Connect-VIServer -Server $Server -user xxx -password "xxx" | Out-Null          $vms = Get-Vm | where {$_.PowerState -eq "PoweredOn"}          $Check = @()          $Check = $Check + $Server + $vms          switch ($Server){               "xx.xx.xx.1" {$delay = 12}               "xx.xx.xx.2" {$delay = 9}               "xx.xx.xx.3" {$delay = 14}               "xx.xx.xx.4" {$delay = 12}               "xx.xx.xx.5" {$delay = 14}               "xx.xx.xx.6" {$delay = 10}               "xx.xx.xx.10" {$delay = 16}               "xx.xx.xx.11" {$delay = 16}               "xx.xx.xx.12" {$delay = 16}          }          For ($i=0; $i -lt $counter; $i++){               $alldata = @()               $stats = Get-Stat -Entity $Check -Realtime -Stat cpu.usage.average -MaxSamples 1               $stats | Group-Object -Property Entity | %{                    $stat = "" | Select Date, HostName, VMName, CPUAvg                    $stat.Date = Get-date                    $stat.VmName = $_.name                    $stat.HostName = $Server                    if ($stat.VmName -eq $Server) {$stat.VmName = $null}                    $cpu = $_.Group | Measure-Object -Property value -Average                    $stat.CPUAvg = [int]$cpu.Average                    $alldata += $stat               }               $alldata | Export-Csv "c:\tmp\$Server.csv" -Append -noTypeInformation               Clear-Variable -Name alldata               Start-Sleep -s $delay          }          Disconnect-VIServer * -Force -Confirm:$false     } -ArgumentList ($Server, $counter)
}

 

Regards

Genoan


Viewing all articles
Browse latest Browse all 251313

Trending Articles



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