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