From f6cf9492e5e56a57d0a553b22275e6b79009ee15 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 25 Jan 2022 11:25:01 +0100 Subject: [PATCH] Moves PerformanceCounter to private space --- doc/100-General/10-Changelog.md | 1 + doc/900-Developer-Guide/00-General.md | 22 +++++++++---------- .../New-IcingaEnvironmentVariable.psm1 | 13 ++++++----- .../Add-IcingaPerformanceCounterCache.psm1 | 6 ++--- ...Get-IcingaPerformanceCounterCacheItem.psm1 | 8 +++++-- .../New-IcingaPerformanceCounterArray.psm1 | 2 +- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index d14ebcb..2e2f150 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -27,6 +27,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#418](https://github.com/Icinga/icinga-powershell-framework/pull/418) Fixes crash on wrong variable usage introduced by [#411](https://github.com/Icinga/icinga-powershell-framework/pull/411) * [#421](https://github.com/Icinga/icinga-powershell-framework/issues/421) Fixes experimental state of `API Check` feature by removing that term and removing the requirement to install `icinga-powershell-restapi` and `icinga-powershell-apichecks` * [#436](https://github.com/Icinga/icinga-powershell-framework/pull/436) Fixes a lookup error for existing plugin documentation files, which caused files not being generated properly in case a similar name was already present on the system +* [#439](https://github.com/Icinga/icinga-powershell-framework/pull/439) Moves PerformanceCounter to private space from previous public, which caused some problems ### Enhancements diff --git a/doc/900-Developer-Guide/00-General.md b/doc/900-Developer-Guide/00-General.md index 547b3b4..f7c5d68 100644 --- a/doc/900-Developer-Guide/00-General.md +++ b/doc/900-Developer-Guide/00-General.md @@ -56,11 +56,12 @@ Everything which should be stored while a daemon is running internally or within The following entries are set by default within the `Private` space: -| Category | Description | -| --- | --- | -| Timers | All created timers by using `Start-IcingaTimer` are stored under this environment variable | -| Scheduler | Once plugins are executed, performance data, check results and exit codes are stored in this section, in case the PowerShell instance is set to run as daemon | -| Daemons | This is a place where all daemon data should be added and stored, separated by a namespace for each module as entry. This data is **not** shared between other daemons | +| Category | Description | +| --- | --- | +| Timers | All created timers by using `Start-IcingaTimer` are stored under this environment variable | +| Scheduler | Once plugins are executed, performance data, check results and exit codes are stored in this section, in case the PowerShell instance is set to run as daemon | +| Daemons | This is a place where all daemon data should be added and stored, separated by a namespace for each module as entry. This data is **not** shared between other daemons | +| PerformanceCounter | A space to share all PerformanceCounter information between threads, which counters are already created for internal usage | #### Example Data @@ -84,12 +85,11 @@ There is no manual configuration required to share the information, as Icinga fo The following entries are set by default within the `Public` space: -| Category | Description | -| --- | --- | -| ThreadPools | A list of all thread pools available to create new thread limits for certain background daemons | -| Daemons | A place to store shared information for each single daemon within a namespace, making data accessible to other threads | -| Threads | A list of all started and available threads running by Icinga for Windows | -| PerformanceCounter | A space to share all PerformanceCounter information between threads, which counters are already created for internal usage | +| Category | Description | +| --- | --- | +| ThreadPools | A list of all thread pools available to create new thread limits for certain background daemons | +| Daemons | A place to store shared information for each single daemon within a namespace, making data accessible to other threads | +| Threads | A list of all started and available threads running by Icinga for Windows | ##### Example Data diff --git a/lib/core/framework/New-IcingaEnvironmentVariable.psm1 b/lib/core/framework/New-IcingaEnvironmentVariable.psm1 index 6c51587..df885b2 100644 --- a/lib/core/framework/New-IcingaEnvironmentVariable.psm1 +++ b/lib/core/framework/New-IcingaEnvironmentVariable.psm1 @@ -33,6 +33,13 @@ function New-IcingaEnvironmentVariable() 'ExitCode' = $null; } ); + + $Global:Icinga.Private.Add( + 'PerformanceCounter', + @{ + 'Cache' = @{ }; + } + ); } # Shared configuration for all threads @@ -42,12 +49,6 @@ function New-IcingaEnvironmentVariable() $Global:Icinga.Public.Add('Daemons', @{ }); $Global:Icinga.Public.Add('Threads', @{ }); $Global:Icinga.Public.Add('ThreadPools', @{ }); - $Global:Icinga.Public.Add( - 'PerformanceCounter', - @{ - 'Cache' = @{ }; - } - ); } # Session specific configuration which should never be modified by users! diff --git a/lib/core/perfcounter/Add-IcingaPerformanceCounterCache.psm1 b/lib/core/perfcounter/Add-IcingaPerformanceCounterCache.psm1 index f47cb39..ca06a8c 100644 --- a/lib/core/perfcounter/Add-IcingaPerformanceCounterCache.psm1 +++ b/lib/core/perfcounter/Add-IcingaPerformanceCounterCache.psm1 @@ -27,10 +27,10 @@ function Add-IcingaPerformanceCounterCache() $Instances ); - if ($Global:Icinga.Public.PerformanceCounter.Cache.ContainsKey($Counter)) { - $Global:Icinga.Public.PerformanceCounter.Cache[$Counter] = $Instances; + if ($Global:Icinga.Private.PerformanceCounter.Cache.ContainsKey($Counter)) { + $Global:Icinga.Private.PerformanceCounter.Cache[$Counter] = $Instances; } else { - $Global:Icinga.Public.PerformanceCounter.Cache.Add( + $Global:Icinga.Private.PerformanceCounter.Cache.Add( $Counter, $Instances ); } diff --git a/lib/core/perfcounter/Get-IcingaPerformanceCounterCacheItem.psm1 b/lib/core/perfcounter/Get-IcingaPerformanceCounterCacheItem.psm1 index 673cbec..0004d2b 100644 --- a/lib/core/perfcounter/Get-IcingaPerformanceCounterCacheItem.psm1 +++ b/lib/core/perfcounter/Get-IcingaPerformanceCounterCacheItem.psm1 @@ -24,8 +24,12 @@ function Get-IcingaPerformanceCounterCacheItem() $Counter ); - if ($Global:Icinga.Public.PerformanceCounter.Cache.ContainsKey($Counter)) { - return $Global:Icinga.Public.PerformanceCounter.Cache[$Counter]; + if ([string]::IsNullOrEmpty($Counter)) { + return $null; + } + + if ($Global:Icinga.Private.PerformanceCounter.Cache.ContainsKey($Counter)) { + return $Global:Icinga.Private.PerformanceCounter.Cache[$Counter]; } return $null; diff --git a/lib/core/perfcounter/New-IcingaPerformanceCounterArray.psm1 b/lib/core/perfcounter/New-IcingaPerformanceCounterArray.psm1 index 77323b4..cca4374 100644 --- a/lib/core/perfcounter/New-IcingaPerformanceCounterArray.psm1 +++ b/lib/core/perfcounter/New-IcingaPerformanceCounterArray.psm1 @@ -56,7 +56,7 @@ function New-IcingaPerformanceCounterArray() # for each session to speed up the loading. This cold be something like # this: # - # $Global:Icinga.Public.PerformanceCounter.Cache += $CounterResult; + # $Global:Icinga.Private.PerformanceCounter.Cache += $CounterResult; # Above we initialise ever single counter and we only require a sleep once # in case a new, yet unknown counter was added