mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-02-03 12:19:29 -05:00
Feature: Changes CPU counter being used for measurement to % Processor Time
This commit is contained in:
parent
cf221c0de0
commit
b8120e5a5a
3 changed files with 30 additions and 13 deletions
|
|
@ -29,6 +29,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
* [#11](https://github.com/Icinga/icinga-powershell-framework/pull/11) Adds feature to update the cache for performance counter instances to keep track of system changes
|
* [#11](https://github.com/Icinga/icinga-powershell-framework/pull/11) Adds feature to update the cache for performance counter instances to keep track of system changes
|
||||||
* [#838](https://github.com/Icinga/icinga-powershell-framework/pull/838) Enhances Icinga for Windows to never load and user PowerShell profiles
|
* [#838](https://github.com/Icinga/icinga-powershell-framework/pull/838) Enhances Icinga for Windows to never load and user PowerShell profiles
|
||||||
* [#841](https://github.com/Icinga/icinga-powershell-framework/pull/841) Adds new [INFO] state for notice and un-checked monitoring objects
|
* [#841](https://github.com/Icinga/icinga-powershell-framework/pull/841) Adds new [INFO] state for notice and un-checked monitoring objects
|
||||||
|
* [#849](https://github.com/Icinga/icinga-powershell-framework/pull/849) Changes CPU provider to use the `\Processor(*)\% Processor Time` counter instead of `\Processor Information(*)\% Processor Utility`
|
||||||
|
|
||||||
## 1.13.3 (2025-05-08)
|
## 1.13.3 (2025-05-08)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,5 +103,6 @@ function New-IcingaEnvironmentVariable()
|
||||||
'FetchedServices' = $FALSE;
|
'FetchedServices' = $FALSE;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
$Global:Icinga.Protected.Add('CPUSockets', (Get-IcingaWindowsInformation Win32_Processor).Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,23 +10,38 @@ function New-IcingaProviderFilterDataCpu()
|
||||||
[switch]$IncludeDetails = $FALSE
|
[switch]$IncludeDetails = $FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
$CpuData = New-IcingaProviderObject -Name 'Cpu';
|
# TODO: Cleanup this mess
|
||||||
$CpuCounter = New-IcingaPerformanceCounterArray '\Processor Information(*)\% Processor Utility';
|
$CpuData = New-IcingaProviderObject -Name 'Cpu';
|
||||||
$CounterStructure = New-IcingaPerformanceCounterStructure -CounterCategory 'Processor Information' -PerformanceCounterHash $CpuCounter;
|
$CpuCounter = New-IcingaPerformanceCounterArray '\Processor(*)\% Processor Time';
|
||||||
[int]$TotalCpuThreads = 0;
|
$CounterStructure = New-IcingaPerformanceCounterStructure -CounterCategory 'Processor' -PerformanceCounterHash $CpuCounter;
|
||||||
[decimal]$TotalCpuLoad = 0;
|
[int]$TotalCpuThreads = 0;
|
||||||
[int]$SocketCount = 0;
|
[decimal]$TotalCpuLoad = 0;
|
||||||
[hashtable]$SocketList = @{ };
|
[int]$SocketCount = 0;
|
||||||
|
[hashtable]$SocketList = @{ };
|
||||||
|
# Store some general data about the CPU sockets and cores. As we moved back to
|
||||||
|
# \Processor(*)\% Processor Time, we need to manually try to map cores to sockets
|
||||||
|
# Remove ony entry from the counter list, which is not a core but the total load entry
|
||||||
|
[int]$NumberOfThreadsPerSocket = ($CpuCounter.Values.Keys.Count - 1) / $Global:Icinga.Protected.CPUSockets;
|
||||||
|
[int]$CurrentSocket = 0;
|
||||||
|
[int]$CurrentThread = 0;
|
||||||
|
[array]$SortedCoreList = $CounterStructure.Keys | Sort-Object { [int]($_ -replace '^\D+', ''); };
|
||||||
|
|
||||||
foreach ($currentcore in $CounterStructure.Keys) {
|
foreach ($currentcore in $SortedCoreList) {
|
||||||
[string]$Socket = $currentcore.Split(',')[0];
|
[string]$CoreId = $currentcore.Trim();
|
||||||
[string]$CoreId = $currentcore.Split(',')[1];
|
|
||||||
[string]$SocketName = [string]::Format('Socket #{0}', $Socket);
|
|
||||||
|
|
||||||
if ($Socket -eq '_Total' -Or $CoreId -eq '_Total') {
|
# We will handle the _Total entry ourselves later
|
||||||
|
if ($CoreId -eq '_Total') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[string]$SocketName = [string]::Format('Socket #{0}', $CurrentSocket);
|
||||||
|
|
||||||
|
$CurrentThread += 1;
|
||||||
|
if ($CurrentThread -ge $NumberOfThreadsPerSocket) {
|
||||||
|
$CurrentSocket += 1;
|
||||||
|
$CurrentThread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ($SocketList.ContainsKey($SocketName) -eq $FALSE) {
|
if ($SocketList.ContainsKey($SocketName) -eq $FALSE) {
|
||||||
$SocketList.Add(
|
$SocketList.Add(
|
||||||
$SocketName,
|
$SocketName,
|
||||||
|
|
@ -41,7 +56,7 @@ function New-IcingaProviderFilterDataCpu()
|
||||||
$CpuData.Metrics | Add-Member -MemberType NoteProperty -Name $SocketName -Value (New-Object PSCustomObject);
|
$CpuData.Metrics | Add-Member -MemberType NoteProperty -Name $SocketName -Value (New-Object PSCustomObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
[decimal]$CoreLoad = $CounterStructure[$currentcore]['% Processor Utility'].value;
|
[decimal]$CoreLoad = $CounterStructure[$CoreId]['% Processor Time'].value;
|
||||||
|
|
||||||
if ($Limit100Percent) {
|
if ($Limit100Percent) {
|
||||||
if ($CoreLoad -gt 100) {
|
if ($CoreLoad -gt 100) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue