|
| 1 | +function Get-IcingaProviderDataValuesCpu() |
| 2 | +{ |
| 3 | + param ( |
| 4 | + [switch]$IncludeDetails = $FALSE |
| 5 | + ); |
| 6 | + |
| 7 | + $CpuData = New-IcingaProviderObject -Name 'Cpu'; |
| 8 | + $CpuCounter = New-IcingaPerformanceCounterArray '\Processor Information(*)\% Processor Utility'; |
| 9 | + $CounterStructure = New-IcingaPerformanceCounterStructure -CounterCategory 'Processor Information' -PerformanceCounterHash $CpuCounter; |
| 10 | + [int]$TotalCpuThreads = 0; |
| 11 | + [decimal]$TotalCpuLoad = 0; |
| 12 | + [hashtable]$SocketList = @{ }; |
| 13 | + |
| 14 | + foreach ($core in $CounterStructure.Keys) { |
| 15 | + [string]$Socket = $core.Split(',')[0]; |
| 16 | + [string]$CoreId = $core.Split(',')[1]; |
| 17 | + [string]$SocketName = [string]::Format('Socket #{0}', $Socket); |
| 18 | + |
| 19 | + if ($Socket -eq '_Total' -Or $CoreId -eq '_Total') { |
| 20 | + continue; |
| 21 | + } |
| 22 | + |
| 23 | + if ($SocketList.ContainsKey($SocketName) -eq $FALSE) { |
| 24 | + $SocketList.Add( |
| 25 | + $SocketName, |
| 26 | + @{ |
| 27 | + 'ThreadCount' = 0; |
| 28 | + 'TotalLoad' = 0; |
| 29 | + } |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + if ((Test-PSCustomObjectMember -PSObject $CpuData.Metrics -Name $SocketName) -eq $FALSE) { |
| 34 | + $CpuData.Metrics | Add-Member -MemberType NoteProperty -Name $SocketName -Value (New-Object PSCustomObject); |
| 35 | + } |
| 36 | + |
| 37 | + [decimal]$CoreLoad = $CounterStructure[$core]['% Processor Utility'].value; |
| 38 | + |
| 39 | + $CpuData.Metrics.$SocketName | Add-Member -MemberType NoteProperty -Name $CoreId -Value $CoreLoad; |
| 40 | + $CpuData.MetricsOverTime.MetricContainer | Add-Member -MemberType NoteProperty -Name $SocketName -Value $null -Force; |
| 41 | + |
| 42 | + $SocketList[$SocketName].ThreadCount += 1; |
| 43 | + $SocketList[$SocketName].TotalLoad += $CoreLoad; |
| 44 | + } |
| 45 | + |
| 46 | + $CpuData.Metadata | Add-Member -MemberType NoteProperty -Name 'Sockets' -Value (New-Object PSCustomObject); |
| 47 | + |
| 48 | + foreach ($entry in $SocketList.Keys) { |
| 49 | + $SocketList[$entry].TotalLoad = $SocketList[$entry].TotalLoad / $SocketList[$entry].ThreadCount; |
| 50 | + $TotalCpuLoad += $SocketList[$entry].TotalLoad; |
| 51 | + $TotalCpuThreads += $SocketList[$entry].ThreadCount; |
| 52 | + |
| 53 | + $CpuData.Metadata.Sockets | Add-Member -MemberType NoteProperty -Name $entry -Value (New-Object PSCustomObject); |
| 54 | + $CpuData.Metadata.Sockets.$entry | Add-Member -MemberType NoteProperty -Name 'Threads' -Value $SocketList[$entry].ThreadCount; |
| 55 | + $CpuData.Metrics.$entry | Add-Member -MemberType NoteProperty -Name 'Total' -Value $SocketList[$entry].TotalLoad; |
| 56 | + } |
| 57 | + |
| 58 | + $CpuData.Metadata | Add-Member -MemberType NoteProperty -Name 'TotalLoad' -Value $TotalCpuLoad; |
| 59 | + $CpuData.Metadata | Add-Member -MemberType NoteProperty -Name 'TotalThreads' -Value $TotalCpuThreads; |
| 60 | + $CpuData.Metadata | Add-Member -MemberType NoteProperty -Name 'CoreDigits' -Value ([string]$TotalCpuThreads).Length; |
| 61 | + $CpuData.Metadata | Add-Member -MemberType NoteProperty -Name 'CoreDetails' -Value (New-Object PSCustomObject); |
| 62 | + |
| 63 | + if ($IncludeDetails) { |
| 64 | + [array]$CPUCIMData = Get-IcingaWindowsInformation Win32_Processor; |
| 65 | + |
| 66 | + foreach ($cpu in $CPUCIMData) { |
| 67 | + if ((Test-PSCustomObjectMember -PSObject $CpuData.Metadata.CoreDetails -Name $cpu.DeviceID) -eq $FALSE) { |
| 68 | + $CpuData.Metadata.CoreDetails | Add-Member -MemberType NoteProperty -Name $cpu.DeviceID -Value (New-Object PSCustomObject); |
| 69 | + } |
| 70 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'Architecture' -Value $cpu.Architecture; |
| 71 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'ProcessorType' -Value $cpu.ProcessorType; |
| 72 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'StatusInfo' -Value $cpu.StatusInfo; |
| 73 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'Family' -Value $cpu.Family; |
| 74 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'CurrentVoltage' -Value $cpu.CurrentVoltage; |
| 75 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'L3CacheSize' -Value $cpu.L3CacheSize; |
| 76 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'L2CacheSize' -Value $cpu.L2CacheSize; |
| 77 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'L2CacheSpeed' -Value $cpu.L2CacheSpeed; |
| 78 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'VoltageCaps' -Value $cpu.VoltageCaps; |
| 79 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'CurrentClockSpeed' -Value $cpu.CurrentClockSpeed; |
| 80 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'Caption' -Value $cpu.Caption; |
| 81 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'Name' -Value $cpu.Name; |
| 82 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'SerialNumber' -Value $cpu.SerialNumber; |
| 83 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'Manufacturer' -Value $cpu.Manufacturer; |
| 84 | + $CpuData.Metadata.CoreDetails.($cpu.DeviceID) | Add-Member -MemberType NoteProperty -Name 'AddressWidth' -Value $cpu.AddressWidth; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + return $CpuData; |
| 89 | +} |
0 commit comments