Skip to content

Commit 611d8a7

Browse files
authored
Merge pull request #392 from Icinga:feature/updates_cpu_plugin_to_report_to_processes
Feature: Adds support to Invoke-IcingaCheckCPU to report top 10 consuming process information 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
2 parents 465c5f2 + c122636 commit 611d8a7

File tree

8 files changed

+97
-31
lines changed

8 files changed

+97
-31
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
*.log
22
*.DS_Store
3-
.vscode
3+
.vscode

config/director/Invoke-IcingaCheckCPU.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

config/director/Plugins_Bundle.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

config/icinga/Invoke-IcingaCheckCPU.conf

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
4848
}}
4949
order = 100
5050
}
51+
"-NoPerfData" = {
52+
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
53+
order = 99
54+
}
5155
"-Core" = {
5256
set_if = {{
5357
var str = macro("$IcingaCheckCPU_String_Core$"); if (len(str) == 0) { return false; }; return true;
@@ -76,8 +80,12 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
7680
value = "$IcingaCheckCPU_Object_Critical$"
7781
order = 3
7882
}
79-
"-NoPerfData" = {
80-
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
83+
"-OverallTotalAsSum" = {
84+
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
85+
order = 99
86+
}
87+
"-DisableProcessList" = {
88+
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
8189
order = 99
8290
}
8391
"-OverallOnly" = {
@@ -87,6 +95,9 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
8795
}
8896
vars.IcingaCheckCPU_Switchparameter_OverallOnly = false
8997
vars.ifw_api_arguments = {
98+
"DisableProcessList" = {
99+
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
100+
}
90101
"ThresholdInterval" = {
91102
value = "$IcingaCheckCPU_String_ThresholdInterval$"
92103
}
@@ -108,10 +119,15 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
108119
"NoPerfData" = {
109120
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
110121
}
122+
"OverallTotalAsSum" = {
123+
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
124+
}
111125
"Verbosity" = {
112126
value = "$IcingaCheckCPU_Int32_Verbosity$"
113127
}
114128
}
129+
vars.IcingaCheckCPU_Switchparameter_DisableProcessList = false
130+
vars.IcingaCheckCPU_Switchparameter_OverallTotalAsSum = false
115131
vars.ifw_api_command = "invoke-icingacheckcpu"
116132
vars.IcingaCheckCPU_Switchparameter_NoPerfData = false
117133
}

config/icinga/Plugins_Bundle.conf

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,7 +3153,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
31533153
order = 99
31543154
}
31553155
"-CriticalTotalSize" = {
3156-
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."
3156+
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."
31573157
value = "$IcingaCheckDirectory_Object_CriticalTotalSize$"
31583158
order = 7
31593159
}
@@ -3353,7 +3353,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
33533353
order = 99
33543354
}
33553355
"-WarningTotalSize" = {
3356-
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."
3356+
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."
33573357
value = "$IcingaCheckDirectory_Object_WarningTotalSize$"
33583358
order = 6
33593359
}
@@ -3363,7 +3363,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
33633363
order = 12
33643364
}
33653365
"-WarningLargestFile" = {
3366-
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."
3366+
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."
33673367
value = "$IcingaCheckDirectory_Object_WarningLargestFile$"
33683368
order = 10
33693369
}
@@ -3378,7 +3378,7 @@ object CheckCommand "Invoke-IcingaCheckDirectory" {
33783378
order = 9
33793379
}
33803380
"-CriticalAverageFile" = {
3381-
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."
3381+
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."
33823382
value = "$IcingaCheckDirectory_Object_CriticalAverageFile$"
33833383
order = 13
33843384
}
@@ -3497,7 +3497,7 @@ object CheckCommand "Invoke-IcingaCheckUNCPath" {
34973497

34983498
arguments += {
34993499
"-WarningTotal" = {
3500-
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"
3500+
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"
35013501
value = "$IcingaCheckUNCPath_Object_WarningTotal$"
35023502
order = 8
35033503
}
@@ -3882,7 +3882,7 @@ object CheckCommand "Invoke-IcingaCheckICMP" {
38823882
order = 99
38833883
}
38843884
"-CriticalPl" = {
3885-
description = "Threshold on which the plugin will return 'CRITICAL' for the response time in ms"
3885+
description = "Threshold on which the plugin will return 'CRITICAL' for possible packet loss in %"
38863886
value = "$IcingaCheckICMP_Object_CriticalPl$"
38873887
order = 5
38883888
}
@@ -4274,6 +4274,10 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
42744274
}}
42754275
order = 100
42764276
}
4277+
"-NoPerfData" = {
4278+
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
4279+
order = 99
4280+
}
42774281
"-Core" = {
42784282
set_if = {{
42794283
var str = macro("$IcingaCheckCPU_String_Core$"); if (len(str) == 0) { return false; }; return true;
@@ -4302,8 +4306,12 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
43024306
value = "$IcingaCheckCPU_Object_Critical$"
43034307
order = 3
43044308
}
4305-
"-NoPerfData" = {
4306-
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
4309+
"-OverallTotalAsSum" = {
4310+
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
4311+
order = 99
4312+
}
4313+
"-DisableProcessList" = {
4314+
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
43074315
order = 99
43084316
}
43094317
"-OverallOnly" = {
@@ -4313,6 +4321,9 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
43134321
}
43144322
vars.IcingaCheckCPU_Switchparameter_OverallOnly = false
43154323
vars.ifw_api_arguments = {
4324+
"DisableProcessList" = {
4325+
set_if = "$IcingaCheckCPU_Switchparameter_DisableProcessList$"
4326+
}
43164327
"ThresholdInterval" = {
43174328
value = "$IcingaCheckCPU_String_ThresholdInterval$"
43184329
}
@@ -4334,10 +4345,15 @@ object CheckCommand "Invoke-IcingaCheckCPU" {
43344345
"NoPerfData" = {
43354346
set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
43364347
}
4348+
"OverallTotalAsSum" = {
4349+
set_if = "$IcingaCheckCPU_Switchparameter_OverallTotalAsSum$"
4350+
}
43374351
"Verbosity" = {
43384352
value = "$IcingaCheckCPU_Int32_Verbosity$"
43394353
}
43404354
}
4355+
vars.IcingaCheckCPU_Switchparameter_DisableProcessList = false
4356+
vars.IcingaCheckCPU_Switchparameter_OverallTotalAsSum = false
43414357
vars.ifw_api_command = "invoke-icingacheckcpu"
43424358
vars.IcingaCheckCPU_Switchparameter_NoPerfData = false
43434359
}
@@ -4773,7 +4789,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
47734789

47744790
arguments += {
47754791
"-WarningRollups" = {
4776-
description = "The warning threshold for the rollup update count on the Windows machine"
4792+
description = "The warning threshold for the total pending update count on the Windows machine"
47774793
value = "$IcingaCheckUpdates_Object_WarningRollups$"
47784794
order = 7
47794795
}
@@ -4791,7 +4807,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
47914807
order = 99
47924808
}
47934809
"-CriticalOther" = {
4794-
description = "The critical threshold for all other updates on the Windows machine"
4810+
description = "The critical threshold for the total pending update count on the Windows machine"
47954811
value = "$IcingaCheckUpdates_Object_CriticalOther$"
47964812
order = 12
47974813
}
@@ -4819,7 +4835,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48194835
order = 100
48204836
}
48214837
"-WarningOther" = {
4822-
description = "The warning threshold for all other updates on the Windows machine"
4838+
description = "The warning threshold for the total pending update count on the Windows machine"
48234839
value = "$IcingaCheckUpdates_Object_WarningOther$"
48244840
order = 11
48254841
}
@@ -4871,12 +4887,12 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48714887
order = 2
48724888
}
48734889
"-WarningSecurity" = {
4874-
description = "The warning threshold for the security update count on the Windows machine"
4890+
description = "The warning threshold for the total pending update count on the Windows machine"
48754891
value = "$IcingaCheckUpdates_Object_WarningSecurity$"
48764892
order = 5
48774893
}
48784894
"-CriticalSecurity" = {
4879-
description = "The critical threshold for the security update count on the Windows machine"
4895+
description = "The critical threshold for the total pending update count on the Windows machine"
48804896
value = "$IcingaCheckUpdates_Object_CriticalSecurity$"
48814897
order = 6
48824898
}

doc/31-Changelog.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1111

1212
### Bugfixes
1313

14+
* [#375](https://github.com/Icinga/icinga-powershell-plugins/pull/375) Fixes a memory leak on the Icinga EventLog provider for fetching Windows EventLog information
1415
* [#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
1516
* [#386](https://github.com/Icinga/icinga-powershell-plugins/pull/386) Adds new provider for Invoke-IcingaCheckEventLog, to improve performance and fix memory leaks
1617

17-
# 1.11.2 (tbd)
18-
19-
### Bugfixes
18+
### Enhancements
2019

21-
* [#375](https://github.com/Icinga/icinga-powershell-plugins/pull/375) Fixes a memory leak on the Icinga EventLog provider for fetching Windows EventLog information
20+
* [#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
2221

2322
# 1.11.1 (2023-11-07)
2423

doc/plugins/04-Invoke-IcingaCheckCPU.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ To execute this plugin you will require to grant the following user permissions.
2929
| Core | String | false | * | Used to specify a single core to check for. For the average load across all cores use `_Total` |
3030
| 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. |
3131
| 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 |
32+
| 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 |
33+
| DisableProcessList | SwitchParameter | false | False | Disables the reporting of the top 10 CPU consuming process list |
3234
| NoPerfData | SwitchParameter | false | False | |
3335
| 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]) |
3436
| 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. |

plugins/Invoke-IcingaCheckCPU.psm1

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
.PARAMETER OverallOnly
3737
If this flag is set, the Warning and Critical thresholds will only apply to the `Overall Load` metric instead of all
3838
returned cores. Requires that the plugin either fetches all cores with `*` or `Total` for the -Core argument
39+
.PARAMETER OverallTotalAsSum
40+
Changes the output of the overall total load to report the sum of all sockets combined instead of the default
41+
average of all sockets
42+
.PARAMETER DisableProcessList
43+
Disables the reporting of the top 10 CPU consuming process list
3944
.PARAMETER Verbosity
4045
Changes the behavior of the plugin output which check states are printed:
4146
0 (default): Only service checks/packages with state not OK will be printed
@@ -54,18 +59,21 @@
5459
function Invoke-IcingaCheckCPU()
5560
{
5661
param (
57-
$Warning = $null,
58-
$Critical = $null,
59-
[string]$Core = '*',
60-
[array]$SocketFilter = @(),
61-
[switch]$OverallOnly = $FALSE,
62+
$Warning = $null,
63+
$Critical = $null,
64+
[string]$Core = '*',
65+
[array]$SocketFilter = @(),
66+
[switch]$OverallOnly = $FALSE,
67+
[switch]$OverallTotalAsSum = $FALSE,
68+
[switch]$DisableProcessList = $FALSE,
6269
[switch]$NoPerfData,
6370
[ValidateSet(0, 1, 2, 3)]
64-
[int]$Verbosity = 0
71+
[int]$Verbosity = 0
6572
);
6673

67-
$CpuData = Get-IcingaProviderDataValuesCpu;
68-
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity;
74+
$CpuData = Get-IcingaProviderDataValuesCpu;
75+
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbose $Verbosity;
76+
$ProcessPackage = New-IcingaCheckPackage -Name 'Top 10 Process CPU usage' -OperatorAnd -Verbose 2 -IgnoreEmptyPackage;
6977

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

107115
if ($Core -eq '*' -Or $Core -Like '*Total*') {
116+
$TotalLoadValue = $CpuData.Metadata.TotalLoad;
117+
118+
if ($OverallTotalAsSum) {
119+
$TotalLoadValue = $CpuData.Metadata.TotalLoadSum;
120+
}
121+
108122
$IcingaCheck = (
109123
New-IcingaCheck `
110124
-Name 'Overall Load' `
111-
-Value $CpuData.Metadata.TotalLoad `
125+
-Value $TotalLoadValue `
112126
-Unit '%' `
113127
-MetricIndex 'totalload' `
114128
-MetricName 'load'
@@ -117,5 +131,24 @@ function Invoke-IcingaCheckCPU()
117131
$CpuPackage.AddCheck($IcingaCheck);
118132
}
119133

134+
if ($DisableProcessList -eq $FALSE) {
135+
$ProcessData = Get-IcingaProviderDataValuesProcess;
136+
[bool]$HasData = $FALSE;
137+
138+
foreach ($cpuProcess in (Get-IcingaProviderElement $ProcessData.Metadata.Hot.Cpu)) {
139+
$HasData = $TRUE;
140+
$ProcessCheck = New-IcingaCheck -Name ([string]::Format('Process {0} with id {1}', $cpuProcess.Value.Name, $cpuProcess.Value.ProcessId)) -Value $cpuProcess.Value.CpuUsage -Unit '%' -NoPerfData;
141+
$ProcessPackage.AddCheck($ProcessCheck);
142+
}
143+
144+
if ($HasData -eq $FALSE) {
145+
$ProcessCheck = New-IcingaCheck -Name 'Process Data' -NoPerfData;
146+
$ProcessCheck.SetOk('No process with high CPU usage found', $TRUE) | Out-Null;
147+
$ProcessPackage.AddCheck($ProcessCheck);
148+
}
149+
150+
$CpuPackage.AddCheck($ProcessPackage);
151+
}
152+
120153
return (New-IcingaCheckResult -Name 'CPU Load' -Check $CpuPackage -NoPerfData $NoPerfData -Compile);
121154
}

0 commit comments

Comments
 (0)