mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
parent
47272bd243
commit
4ada0d69f9
3 changed files with 58 additions and 21 deletions
39
lib/core/perfcounter/Icinga_GlobalPerfCounterCache.psm1
Normal file
39
lib/core/perfcounter/Icinga_GlobalPerfCounterCache.psm1
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
function New-IcingaPerformanceCounterCache()
|
||||||
|
{
|
||||||
|
if ($null -eq $global:Icinga_PerfCounterCache) {
|
||||||
|
$global:Icinga_PerfCounterCache = (
|
||||||
|
[hashtable]::Synchronized(
|
||||||
|
@{}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Add-IcingaPerformanceCounterCache()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
$Counter,
|
||||||
|
$Instances
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($global:Icinga_PerfCounterCache.ContainsKey($Counter)) {
|
||||||
|
$global:Icinga_PerfCounterCache[$Counter] = $Instances;
|
||||||
|
} else {
|
||||||
|
$global:Icinga_PerfCounterCache.Add(
|
||||||
|
$Counter, $Instances
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-IcingaPerformanceCounterCacheItem()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
$Counter
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($global:Icinga_PerfCounterCache.ContainsKey($Counter)) {
|
||||||
|
return $global:Icinga_PerfCounterCache[$Counter];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
|
@ -54,10 +54,11 @@ function New-IcingaPerformanceCounter()
|
||||||
# have been found
|
# have been found
|
||||||
if ($UseCounterInstance -eq '*') {
|
if ($UseCounterInstance -eq '*') {
|
||||||
# In case we already loaded the counters once, return the finished array
|
# In case we already loaded the counters once, return the finished array
|
||||||
# TODO: Re-Implement caching for counters
|
$CachedCounter = Get-IcingaPerformanceCounterCacheItem -Counter $Counter;
|
||||||
<#if ($Icinga2.Cache.PerformanceCounter.ContainsKey($Counter) -eq $TRUE) {
|
|
||||||
return (New-IcingaPerformanceCounterResult -FullName $Counter -PerformanceCounters $Icinga2.Cache.PerformanceCounter[$Counter]);
|
if ($null -ne $CachedCounter) {
|
||||||
}#>
|
return (New-IcingaPerformanceCounterResult -FullName $Counter -PerformanceCounters $CachedCounter);
|
||||||
|
}
|
||||||
|
|
||||||
# If we need to build the array, load all instances from the counters and
|
# If we need to build the array, load all instances from the counters and
|
||||||
# create single performance counters and add them to a custom array and
|
# create single performance counters and add them to a custom array and
|
||||||
|
|
@ -88,8 +89,7 @@ function New-IcingaPerformanceCounter()
|
||||||
# Add the parent counter including the array of Performance Counters to our
|
# Add the parent counter including the array of Performance Counters to our
|
||||||
# caching mechanism and return the New-IcingaPerformanceCounterResult object for usage
|
# caching mechanism and return the New-IcingaPerformanceCounterResult object for usage
|
||||||
# within the monitoring modules
|
# within the monitoring modules
|
||||||
# TODO: Re-Implement caching for counters
|
Add-IcingaPerformanceCounterCache -Counter $Counter -Instances $AllCountersIntances;
|
||||||
# $Icinga2.Cache.PerformanceCounter.Add($Counter, $AllCountersIntances);
|
|
||||||
return (New-IcingaPerformanceCounterResult -FullName $Counter -PerformanceCounters $AllCountersIntances);
|
return (New-IcingaPerformanceCounterResult -FullName $Counter -PerformanceCounters $AllCountersIntances);
|
||||||
} else {
|
} else {
|
||||||
# This part will handle the counters without any instances as well as
|
# This part will handle the counters without any instances as well as
|
||||||
|
|
@ -97,23 +97,21 @@ function New-IcingaPerformanceCounter()
|
||||||
|
|
||||||
# In case we already have the counter within our cache, return the
|
# In case we already have the counter within our cache, return the
|
||||||
# cached informations
|
# cached informations
|
||||||
# TODO: Re-Implement caching for counters
|
$CachedCounter = Get-IcingaPerformanceCounterCacheItem -Counter $Counter;
|
||||||
<#if ($Icinga2.Cache.PerformanceCounter.ContainsKey($Counter) -eq $TRUE) {
|
|
||||||
return $Icinga2.Cache.PerformanceCounter[$Counter];
|
if ($null -ne $CachedCounter) {
|
||||||
}#>
|
return $CachedCounter;
|
||||||
|
}
|
||||||
|
|
||||||
# If the cache is not present yet, create the Performance Counter object,
|
# If the cache is not present yet, create the Performance Counter object,
|
||||||
# and add it to our cache
|
# and add it to our cache
|
||||||
$NewCounter = New-IcingaPerformanceCounterObject -FullName $Counter -Category $UseCounterCategory -Counter $UseCounterName -Instance $UseCounterInstance -SkipWait $SkipWait;
|
$NewCounter = New-IcingaPerformanceCounterObject -FullName $Counter -Category $UseCounterCategory -Counter $UseCounterName -Instance $UseCounterInstance -SkipWait $SkipWait;
|
||||||
# TODO: Re-Implement caching for counters
|
Add-IcingaPerformanceCounterCache -Counter $Counter -Instances $NewCounter;
|
||||||
#$Icinga2.Cache.PerformanceCounter.Add($Counter, $NewCounter);
|
|
||||||
return $NewCounter; #TODO: Remove once caching is implemented
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# This function will always return non-instance counters or
|
# This function will always return non-instance counters or
|
||||||
# specificly defined instance counters. Performance Counter Arrays
|
# specificly defined instance counters. Performance Counter Arrays
|
||||||
# are returned within their function. This is just to ensure that the
|
# are returned within their function. This is just to ensure that the
|
||||||
# function looks finished from developer point of view
|
# function looks finished from developer point of view
|
||||||
# TODO: Re-Implement caching for counters, right now we return $NewCounter by default
|
return (Get-IcingaPerformanceCounterCacheItem -Counter $Counter);
|
||||||
#return $Icinga2.Cache.PerformanceCounter[$Counter];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ function New-IcingaPerformanceCounterArray()
|
||||||
# NumOfCounters * 500 milliseconds for the first runs. This will speed
|
# NumOfCounters * 500 milliseconds for the first runs. This will speed
|
||||||
# up the general loading of counters and will not require some fancy
|
# up the general loading of counters and will not require some fancy
|
||||||
# pre-caching / configuration handler
|
# pre-caching / configuration handler
|
||||||
# TODO: Re-Implement caching for counters
|
$CachedCounter = Get-IcingaPerformanceCounterCacheItem -Counter $Counter;
|
||||||
#if ($Icinga2.Cache.PerformanceCounter -ne $null) {
|
|
||||||
# if ($Icinga2.Cache.PerformanceCounter.ContainsKey($counter) -eq $TRUE) {
|
if ($null -ne $CachedCounter) {
|
||||||
$RequireSleep = $FALSE;
|
$RequireSleep = $FALSE;
|
||||||
# }
|
}
|
||||||
#}
|
|
||||||
$obj = New-IcingaPerformanceCounter -Counter $counter -SkipWait $TRUE;
|
$obj = New-IcingaPerformanceCounter -Counter $counter -SkipWait $TRUE;
|
||||||
if ($CounterResult.ContainsKey($obj.Name()) -eq $FALSE) {
|
if ($CounterResult.ContainsKey($obj.Name()) -eq $FALSE) {
|
||||||
$CounterResult.Add($obj.Name(), $obj.Value());
|
$CounterResult.Add($obj.Name(), $obj.Value());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue