Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.log
*.DS_Store
.vscode
.vscode
2 changes: 1 addition & 1 deletion config/director/Invoke-IcingaCheckCPU.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/director/Plugins_Bundle.json

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions config/icinga/Invoke-IcingaCheckCPU.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
}}
order = 100
}
"-NoPerfData" = {
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
order = 99
}
"-Core" = {
set_if = {{
var str = macro("$IcingaCheckCPU_String_Core$"); if (len(str) == 0) { return false; }; return true;
Expand Down Expand Up @@ -76,8 +80,12 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
value = "$IcingaCheckCPU_Object_Critical$"
order = 3
}
"-NoPerfData" = {
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
"-OverallTotalAsSum" = {
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
order = 99
}
"-DisableProcessList" = {
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
order = 99
}
"-OverallOnly" = {
Expand All @@ -87,6 +95,9 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
}
vars.IcingaCheckCPU_Switchparameter_OverallOnly = false
vars.ifw_api_arguments = {
"DisableProcessList" = {
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
}
"ThresholdInterval" = {
value = "$IcingaCheckCPU_String_ThresholdInterval$"
}
Expand All @@ -108,10 +119,15 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
"NoPerfData" = {
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
}
"OverallTotalAsSum" = {
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
}
"Verbosity" = {
value = "$IcingaCheckCPU_Int32_Verbosity$"
}
}
vars.IcingaCheckCPU_Switchparameter_DisableProcessList = false
vars.IcingaCheckCPU_Switchparameter_OverallTotalAsSum = false
vars.ifw_api_command = "invoke-icingacheckcpu"
vars.IcingaCheckCPU_Switchparameter_NoPerfData = false
}
42 changes: 29 additions & 13 deletions config/icinga/Plugins_Bundle.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3153,7 +3153,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
order = 99
}
"-CriticalTotalSize" = {
description = "Checks the resulting file count of the provided filters and input and returns critical for the provided threshold. Follows the Icinga plugin threshold guidelines."
description = "Checks the total folder size of all files of the provided filters and input and returns critical for the provided threshold. Follows the Icinga plugin threshold guidelines."
value = "$IcingaCheckDirectory_Object_CriticalTotalSize$"
order = 7
}
Expand Down Expand Up @@ -3353,7 +3353,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
order = 99
}
"-WarningTotalSize" = {
description = "Checks the resulting file count of the provided filters and input and returns warning for the provided threshold. Follows the Icinga plugin threshold guidelines."
description = "Checks the total folder size of all files of the provided filters and input and returns warning for the provided threshold. Follows the Icinga plugin threshold guidelines."
value = "$IcingaCheckDirectory_Object_WarningTotalSize$"
order = 6
}
Expand All @@ -3363,7 +3363,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
order = 12
}
"-WarningLargestFile" = {
description = "Checks the largest file size found for the given filters and input and returns warning for the provided threshold. Follows the Icinga plugin threshold guidelines."
description = "Checks the resulting file count of the provided filters and input and returns warning for the provided threshold. Follows the Icinga plugin threshold guidelines."
value = "$IcingaCheckDirectory_Object_WarningLargestFile$"
order = 10
}
Expand All @@ -3378,7 +3378,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
order = 9
}
"-CriticalAverageFile" = {
description = "Checks the resulting file count of the provided filters and input and returns critical for the provided threshold. Follows the Icinga plugin threshold guidelines."
description = "Checks the average file size found for the given filters and input and returns critical for the provided threshold. Follows the Icinga plugin threshold guidelines."
value = "$IcingaCheckDirectory_Object_CriticalAverageFile$"
order = 13
}
Expand Down Expand Up @@ -3497,7 +3497,7 @@ object CheckCommand "Invoke-IcingaCheckUNCPath" {

arguments += {
"-WarningTotal" = {
description = "A warning threshold for the shares total free space in byte units, like '50GB:' Please note that this value is decreasing over time, therefor you will have to use the plugin handler and add ':' at the end of your input to check for 'current value < threshold' like in the previous example Allowed units: B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB"
description = "A warning threshold for the shares free space in either % or byte units, like '20%:' or '50GB:' Please note that this value is decreasing over time, therefor you will have to use the plugin handler and add ':' at the end of your input to check for 'current value < threshold' like in the previous example Allowed units: %, B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB"
value = "$IcingaCheckUNCPath_Object_WarningTotal$"
order = 8
}
Expand Down Expand Up @@ -3882,7 +3882,7 @@ object CheckCommand "Invoke-IcingaCheckICMP" {
order = 99
}
"-CriticalPl" = {
description = "Threshold on which the plugin will return 'CRITICAL' for the response time in ms"
description = "Threshold on which the plugin will return 'CRITICAL' for possible packet loss in %"
value = "$IcingaCheckICMP_Object_CriticalPl$"
order = 5
}
Expand Down Expand Up @@ -4274,6 +4274,10 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
}}
order = 100
}
"-NoPerfData" = {
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
order = 99
}
"-Core" = {
set_if = {{
var str = macro("$IcingaCheckCPU_String_Core$"); if (len(str) == 0) { return false; }; return true;
Expand Down Expand Up @@ -4302,8 +4306,12 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
value = "$IcingaCheckCPU_Object_Critical$"
order = 3
}
"-NoPerfData" = {
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
"-OverallTotalAsSum" = {
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
order = 99
}
"-DisableProcessList" = {
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
order = 99
}
"-OverallOnly" = {
Expand All @@ -4313,6 +4321,9 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
}
vars.IcingaCheckCPU_Switchparameter_OverallOnly = false
vars.ifw_api_arguments = {
"DisableProcessList" = {
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
}
"ThresholdInterval" = {
value = "$IcingaCheckCPU_String_ThresholdInterval$"
}
Expand All @@ -4334,10 +4345,15 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
"NoPerfData" = {
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
}
"OverallTotalAsSum" = {
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
}
"Verbosity" = {
value = "$IcingaCheckCPU_Int32_Verbosity$"
}
}
vars.IcingaCheckCPU_Switchparameter_DisableProcessList = false
vars.IcingaCheckCPU_Switchparameter_OverallTotalAsSum = false
vars.ifw_api_command = "invoke-icingacheckcpu"
vars.IcingaCheckCPU_Switchparameter_NoPerfData = false
}
Expand Down Expand Up @@ -4773,7 +4789,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {

arguments += {
"-WarningRollups" = {
description = "The warning threshold for the rollup update count on the Windows machine"
description = "The warning threshold for the total pending update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_WarningRollups$"
order = 7
}
Expand All @@ -4791,7 +4807,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
order = 99
}
"-CriticalOther" = {
description = "The critical threshold for all other updates on the Windows machine"
description = "The critical threshold for the total pending update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_CriticalOther$"
order = 12
}
Expand Down Expand Up @@ -4819,7 +4835,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
order = 100
}
"-WarningOther" = {
description = "The warning threshold for all other updates on the Windows machine"
description = "The warning threshold for the total pending update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_WarningOther$"
order = 11
}
Expand Down Expand Up @@ -4871,12 +4887,12 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
order = 2
}
"-WarningSecurity" = {
description = "The warning threshold for the security update count on the Windows machine"
description = "The warning threshold for the total pending update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_WarningSecurity$"
order = 5
}
"-CriticalSecurity" = {
description = "The critical threshold for the security update count on the Windows machine"
description = "The critical threshold for the total pending update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_CriticalSecurity$"
order = 6
}
Expand Down
7 changes: 3 additions & 4 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

### Bugfixes

* [#375](https://github.com/Icinga/icinga-powershell-plugins/pull/375) Fixes a memory leak on the Icinga EventLog provider for fetching Windows EventLog information
* [#384](https://github.com/Icinga/icinga-powershell-plugins/pull/384) Adds new data provider for Invoke-IcingaCheckProcess and extends functionality by adding a new 'ExcludeProcess' argument
* [#386](https://github.com/Icinga/icinga-powershell-plugins/pull/386) Adds new provider for Invoke-IcingaCheckEventLog, to improve performance and fix memory leaks

# 1.11.2 (tbd)

### Bugfixes
### Enhancements

* [#375](https://github.com/Icinga/icinga-powershell-plugins/pull/375) Fixes a memory leak on the Icinga EventLog provider for fetching Windows EventLog information
* [#366](https://github.com/Icinga/icinga-powershell-plugins/issues/366) Adds support to `Invoke-IcingaCheckCPU` to report top CPU consuming process information as well as a switch to change the overall load from average to sum

# 1.11.1 (2023-11-07)

Expand Down
2 changes: 2 additions & 0 deletions doc/plugins/04-Invoke-IcingaCheckCPU.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ To execute this plugin you will require to grant the following user permissions.
| Core | String | false | * | Used to specify a single core to check for. For the average load across all cores use `_Total` |
| SocketFilter | Array | false | @() | Allows to specify one or mutlitple sockets by using their socket id. Not matching socket id's will not be evaluated<br /> by the plugin. |
| OverallOnly | SwitchParameter | false | False | If this flag is set, the Warning and Critical thresholds will only apply to the `Overall Load` metric instead of all<br /> returned cores. Requires that the plugin either fetches all cores with `*` or `Total` for the -Core argument |
| OverallTotalAsSum | SwitchParameter | false | False | Changes the output of the overall total load to report the sum of all sockets combined instead of the default<br /> average of all sockets |
| DisableProcessList | SwitchParameter | false | False | Disables the reporting of the top 10 CPU consuming process list |
| NoPerfData | SwitchParameter | false | False | |
| Verbosity | Int32 | false | 0 | Changes the behavior of the plugin output which check states are printed:<br /> 0 (default): Only service checks/packages with state not OK will be printed<br /> 1: Only services with not OK will be printed including OK checks of affected check packages including Package config<br /> 2: Everything will be printed regardless of the check state<br /> 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK]) |
| ThresholdInterval | String | | | Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described [here](https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/). An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring. |
Expand Down
51 changes: 42 additions & 9 deletions plugins/Invoke-IcingaCheckCPU.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
.PARAMETER OverallOnly
If this flag is set, the Warning and Critical thresholds will only apply to the `Overall Load` metric instead of all
returned cores. Requires that the plugin either fetches all cores with `*` or `Total` for the -Core argument
.PARAMETER OverallTotalAsSum
Changes the output of the overall total load to report the sum of all sockets combined instead of the default
average of all sockets
.PARAMETER DisableProcessList
Disables the reporting of the top 10 CPU consuming process list
.PARAMETER Verbosity
Changes the behavior of the plugin output which check states are printed:
0 (default): Only service checks/packages with state not OK will be printed
Expand All @@ -54,18 +59,21 @@
function Invoke-IcingaCheckCPU()
{
param (
$Warning = $null,
$Critical = $null,
[string]$Core = '*',
[array]$SocketFilter = @(),
[switch]$OverallOnly = $FALSE,
$Warning = $null,
$Critical = $null,
[string]$Core = '*',
[array]$SocketFilter = @(),
[switch]$OverallOnly = $FALSE,
[switch]$OverallTotalAsSum = $FALSE,
[switch]$DisableProcessList = $FALSE,
[switch]$NoPerfData,
[ValidateSet(0, 1, 2, 3)]
[int]$Verbosity = 0
[int]$Verbosity = 0
);

$CpuData = Get-IcingaProviderDataValuesCpu;
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity;
$CpuData = Get-IcingaProviderDataValuesCpu;
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity;
$ProcessPackage = New-IcingaCheckPackage -Name 'Top 10 Process CPU usage' -OperatorAnd -Verbose 2 -IgnoreEmptyPackage;

foreach ($socket in (Get-IcingaProviderElement $CpuData.Metrics)) {
[string]$SocketId = $socket.Name.Replace('Socket #', '');
Expand Down Expand Up @@ -105,10 +113,16 @@ function Invoke-IcingaCheckCPU()
}

if ($Core -eq '*' -Or $Core -Like '*Total*') {
$TotalLoadValue = $CpuData.Metadata.TotalLoad;

if ($OverallTotalAsSum) {
$TotalLoadValue = $CpuData.Metadata.TotalLoadSum;
}

$IcingaCheck = (
New-IcingaCheck `
-Name 'Overall Load' `
-Value $CpuData.Metadata.TotalLoad `
-Value $TotalLoadValue `
-Unit '%' `
-MetricIndex 'totalload' `
-MetricName 'load'
Expand All @@ -117,5 +131,24 @@ function Invoke-IcingaCheckCPU()
$CpuPackage.AddCheck($IcingaCheck);
}

if ($DisableProcessList -eq $FALSE) {
$ProcessData = Get-IcingaProviderDataValuesProcess;
[bool]$HasData = $FALSE;

foreach ($cpuProcess in (Get-IcingaProviderElement $ProcessData.Metadata.Hot.Cpu)) {
$HasData = $TRUE;
$ProcessCheck = New-IcingaCheck -Name ([string]::Format('Process {0} with id {1}', $cpuProcess.Value.Name, $cpuProcess.Value.ProcessId)) -Value $cpuProcess.Value.CpuUsage -Unit '%' -NoPerfData;
$ProcessPackage.AddCheck($ProcessCheck);
}

if ($HasData -eq $FALSE) {
$ProcessCheck = New-IcingaCheck -Name 'Process Data' -NoPerfData;
$ProcessCheck.SetOk('No process with high CPU usage found', $TRUE) | Out-Null;
$ProcessPackage.AddCheck($ProcessCheck);
}

$CpuPackage.AddCheck($ProcessPackage);
}

return (New-IcingaCheckResult -Name 'CPU Load' -Check $CpuPackage -NoPerfData $NoPerfData -Compile);
}