icinga-powershell-framework/lib/icinga/plugin/New-IcingaCheckResult.psm1
Lord Hepipud f5d9ac943c
Adds improved handling for Metrics over Time (#772)
This adds new and improved handling for Metrics over Time.

The overall execution time for the background tasks has been reduced, while also the memory management is way more efficient.

In addition to the improved core handling of the feature, performance metrics for metrics over time will NO LONGER BE WRITTEN.

This will increase the performance of the graphing solutions like InfluxDB a lot, while the monitoring by using the "-ThresholdInterval" argument is still possible.

```powershell
PS> Invoke-IcingaCheckCPU -Warning '5%' -ThresholdInterval '10m';
[WARNING] CPU Load [WARNING] Overall Load, Socket #0
\_ [WARNING] Overall Load: Value 6.546175% is greater than threshold 5% (10m Avg.) 
\_ [WARNING] Socket #0 
     \_ [WARNING] Core 0: Value 18.391566% is greater than threshold 5% (10m Avg.) 
     \_ [WARNING] Core 1: Value 14.100505% is greater than threshold 5% (10m Avg.)
     \_ [WARNING] Core Total: Value 6.546175% is greater than threshold 5% (10m Avg.)
| totalload::ifw_cpu::load=5.804053;5;;0;100 0_0::ifw_cpu::load=18.03764;5;;0;100 0_1::ifw_cpu::load=9.36611;5;;0;100 0_2::ifw_cpu::load=5.830669;5;;0;100 0_3::ifw_cpu::load=0.646737;5;;0;100 0_4::ifw_cpu::load=0.926955;5;;0;100 0_5::ifw_cpu::load=0.016205;5;;0;100 0_total::ifw_cpu::load=5.804053;5;;0;100
```
2025-01-29 14:45:53 +01:00

61 lines
2.1 KiB
PowerShell

function New-IcingaCheckResult()
{
param (
$Check,
[bool]$NoPerfData = $FALSE,
[switch]$Compile = $FALSE
);
$IcingaCheckResult = New-Object -TypeName PSObject;
$IcingaCheckResult | Add-Member -MemberType NoteProperty -Name 'Check' -Value $Check;
$IcingaCheckResult | Add-Member -MemberType NoteProperty -Name 'NoPerfData' -Value $NoPerfData;
$IcingaCheckResult | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
# Always ensure our cache is cleared before compiling new check data
Get-IcingaCheckSchedulerPluginOutput | Out-Null;
Get-IcingaCheckSchedulerPerfData | Out-Null;
if ($null -eq $this.Check) {
return $IcingaEnums.IcingaExitCode.Unknown;
}
# Compile the check / package if not already done
$this.Check.Compile();
Write-IcingaPluginOutput -Output ($this.Check.__GetCheckOutput());
if ($this.NoPerfData -eq $FALSE) {
Write-IcingaPluginPerfData -IcingaCheck $this.Check;
}
# Clear our metrics over time cache, as we need to load them again for the next
# plugin execution
$Global:Icinga.Private.Scheduler.PerfDataWriter.MetricsOverTime = '';
# Ensure we reset our internal cache once the plugin was executed
$CheckCommand = $this.Check.__GetCheckCommand();
if ([string]::IsNullOrEmpty($CheckCommand) -eq $FALSE -And $Global:Icinga.Private.Scheduler.ThresholdCache.ContainsKey($CheckCommand)) {
$Global:Icinga.Private.Scheduler.ThresholdCache[$CheckCommand] = $null;
}
# Reset the current execution date
$Global:Icinga.CurrentDate = $null;
$ExitCode = $this.Check.__GetCheckState();
Set-IcingaInternalPluginExitCode -ExitCode $ExitCode;
$this.Check = $null;
return $ExitCode;
}
if ($Compile) {
$IcingaExitCode = $IcingaCheckResult.Compile();
$IcingaCheckResult = $null;
$Check = $null;
return $IcingaExitCode;
}
return $IcingaCheckResult;
}