From 5e0a5274468a6ca9c5cdce8b0c4b60b70ebb0773 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Thu, 29 Jun 2023 13:35:35 +0200 Subject: [PATCH] Updates CPU check to new provider --- doc/31-Changelog.md | 8 +++++++ plugins/Invoke-IcingaCheckCPU.psm1 | 38 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index b6a99efe..2e054bc3 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -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 diff --git a/plugins/Invoke-IcingaCheckCPU.psm1 b/plugins/Invoke-IcingaCheckCPU.psm1 index 3cd1561f..778e4123 100644 --- a/plugins/Invoke-IcingaCheckCPU.psm1 +++ b/plugins/Invoke-IcingaCheckCPU.psm1 @@ -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);