icinga-powershell-framework/lib/core/framework/New-IcingaEnvironmentVariable.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

107 lines
3.6 KiB
PowerShell

<#
.SYNOPSIS
Creates all environment variables for Icinga for Windows for the
PowerShell session
.DESCRIPTION
Creates all environment variables for Icinga for Windows for the
PowerShell session
.EXAMPLE
New-IcingaEnvironmentVariable;
#>
function New-IcingaEnvironmentVariable()
{
if ($null -eq $Global:Icinga) {
$Global:Icinga = @{ };
}
if ($Global:Icinga.ContainsKey('CacheBuilding') -eq $FALSE) {
$Global:Icinga.Add('CacheBuilding', $FALSE);
}
# Session specific configuration for this shell
if ($Global:Icinga.ContainsKey('Private') -eq $FALSE) {
$Global:Icinga.Add('Private', @{ });
$Global:Icinga.Private.Add('Daemons', @{ });
$Global:Icinga.Private.Add('Documentation', @{ });
$Global:Icinga.Private.Add('Timers', @{ });
$Global:Icinga.Private.Add('ProgressStatus', @{ });
$Global:Icinga.Private.Add(
'RepositoryStatus',
@{
'FailedRepositories' = @{ };
}
);
$Global:Icinga.Private.Add(
'Scheduler',
@{
'CheckCommand' = '';
'CheckData' = @{ };
'ThresholdCache' = @{ };
'CheckResults' = @();
'PerformanceData' = '';
'PluginException' = $null;
'ExitCode' = $null;
'PerfDataWriter' = @{
'Cache' = @{ };
'Storage' = (New-Object System.Text.StringBuilder);
'Daemon' = @{ };
'MetricsOverTime' = '';
}
}
);
$Global:Icinga.Private.Add(
'PerformanceCounter',
@{
'Cache' = @{ };
}
);
}
# Shared configuration for all threads
if ($Global:Icinga.ContainsKey('Public') -eq $FALSE) {
$Global:Icinga.Add('Public', [hashtable]::Synchronized(@{ }));
$Global:Icinga.Public.Add('Daemons', @{ });
$Global:Icinga.Public.Add('Threads', @{ });
$Global:Icinga.Public.Add('ThreadPools', @{ });
$Global:Icinga.Public.Add('ThreadAliveHousekeeping', @{ });
}
# Session specific configuration which should never be modified by users!
if ($Global:Icinga.ContainsKey('Protected') -eq $FALSE) {
$Global:Icinga.Add('Protected', @{ });
$Global:Icinga.Protected.Add('DeveloperMode', $FALSE);
$Global:Icinga.Protected.Add('DebugMode', $FALSE);
$Global:Icinga.Protected.Add('JEAContext', $FALSE);
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
$Global:Icinga.Protected.Add('Minimal', $FALSE);
$Global:Icinga.Protected.Add('ThreadName', '');
$Global:Icinga.Protected.Add('GarbageCollector', @{ });
$Global:Icinga.Protected.Add(
'Environment', @{
'Icinga Service' = @{
'Status' = '';
'Present' = $FALSE;
'Name' = 'icinga2';
'DisplayName' = 'icinga2';
'User' = 'NT Authority\NetworkService';
'ServicePath' = '';
};
'PowerShell Service' = @{
'Status' = '';
'Present' = $FALSE;
'Name' = 'icingapowershell';
'DisplayName' = 'icingapowershell';
'User' = 'NT Authority\NetworkService';
'ServicePath' = '';
};
'FetchedServices' = $FALSE;
}
);
}
}