Skip to content

Commit

Permalink
Updates CPU check to new provider
Browse files Browse the repository at this point in the history
  • Loading branch information
LordHepipud committed Jun 29, 2023
1 parent df37c12 commit 5e0a527
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
8 changes: 8 additions & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Enhancements

* [#332](https://github.com/Icinga/icinga-powershell-plugins/issues/332) Adds support to provide different credentials for the `Invoke-IcingaCheckUNCPath` plugin, to run the check for a different user account
* [#355](https://github.com/Icinga/icinga-powershell-plugins/pull/355) Updates `Invoke-IcingaCheckCPU` to use new data providers directly from the Icinga PowerShell Framework.

### Breaking changes

#### Invoke-IcingaCheckCPU

* The new CPU metrics will now be separated between the actual sockets of the system, allowing an overview on multi socket systems, which CPU is assigned more loads
* Metrics will now be separated by `0_1` for the index, which in this example is socket 0 and core 1.

### Enhancements

Expand Down
38 changes: 28 additions & 10 deletions plugins/Invoke-IcingaCheckCPU.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,39 @@ function Invoke-IcingaCheckCPU()
[int]$Verbosity = 0
);

$CpuCounter = New-IcingaPerformanceCounterArray '\Processor(*)\% processor time';
$CounterStructure = New-IcingaPerformanceCounterStructure -CounterCategory 'Processor' -PerformanceCounterHash $CpuCounter;
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity;
[int]$CpuCount = ([string](Get-IcingaCPUCount -CounterArray $CounterStructure)).Length;
$CpuData = Get-IcingaProviderDataValuesCpu;
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity;

foreach ($counter in $CounterStructure.Keys) {
if ($Core -ne '*' -And $counter -ne $Core) {
continue;
foreach ($socket in (Get-IcingaProviderElement $CpuData.Metrics)) {
$SocketPackage = New-IcingaCheckPackage -Name $socket.Name -OperatorAnd -Verbose $Verbosity;

foreach ($thread in (Get-IcingaProviderElement $socket.Value)) {
if ($Core -ne '*' -And $thread.Name -ne $Core) {
continue;
}

$IcingaCheck = (
New-IcingaCheck `
-Name ([string]::Format('Core {0}', (Format-IcingaDigitCount -Value $thread.Name -Digits $CpuData.Metadata.CoreDigits -Symbol ' '))) `
-Value $thread.Value `
-Unit '%' `
-MetricIndex ([string]::Format('{0}_{1}', $socket.Name.Replace('Socket #', ''), $thread.Name)) `
-MetricName 'load'
).WarnOutOfRange($Warning).CritOutOfRange($Critical);

$SocketPackage.AddCheck($IcingaCheck);
}

$CpuPackage.AddCheck($SocketPackage);
}

if ($Core -eq '*' -Or $Core -Like '*Total*') {
$IcingaCheck = (
New-IcingaCheck `
-Name ([string]::Format('Core {0}', (Format-IcingaDigitCount -Value $counter.Replace('_', '') -Digits $CpuCount -Symbol ' '))) `
-Value $CounterStructure[$counter]['% processor time'].value `
-Name 'Overall Load' `
-Value $CpuData.Metadata.TotalLoad `
-Unit '%' `
-MetricIndex ($counter.Replace('_', '')) `
-MetricIndex 'totalload' `
-MetricName 'load'
).WarnOutOfRange($Warning).CritOutOfRange($Critical);

Expand Down

0 comments on commit 5e0a527

Please sign in to comment.