mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
First attempt for CPU load check
This commit is contained in:
parent
8103341388
commit
756a1284e3
1 changed files with 30 additions and 0 deletions
30
lib/plugins/Invoke-IcingaCheckCPU.psm1
Normal file
30
lib/plugins/Invoke-IcingaCheckCPU.psm1
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
Import-IcingaLib core\perfcounter;
|
||||||
|
Import-IcingaLib icinga\plugin;
|
||||||
|
|
||||||
|
function Invoke-IcingaCheckCPU()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
$Warning,
|
||||||
|
$Critical,
|
||||||
|
$Core = '*',
|
||||||
|
[switch]$NoPerfData,
|
||||||
|
$Verbose
|
||||||
|
);
|
||||||
|
|
||||||
|
$CpuCounter = New-IcingaPerformanceCounter -Counter ([string]::Format('\Processor({0})\% processor time', $Core));
|
||||||
|
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbos $Verbose;
|
||||||
|
|
||||||
|
if ($CpuCounter.Counters.Count -ne 0) {
|
||||||
|
foreach ($counter in $CpuCounter.Counters) {
|
||||||
|
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Core #{0}', $counter.Instance)) -Value $counter.Value().Value -Unit '%';
|
||||||
|
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||||
|
$CpuPackage.AddCheck($IcingaCheck);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Core #{0}',$Core)) -Value $CpuCounter.Value().Value -Unit '%';
|
||||||
|
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||||
|
$CpuPackage.AddCheck($IcingaCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit (New-IcingaCheckResult -Name 'CPU Load' -Check $CpuPackage -NoPerfData $NoPerfData -Compile);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue