mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
parent
2533464aa6
commit
3bf87c2f2a
7 changed files with 201 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
* Adds new Cmdlet `Show-IcingaPerformanceCounterInstances` to display all available instances for Performance Counters
|
* Adds new Cmdlet `Show-IcingaPerformanceCounterInstances` to display all available instances for Performance Counters
|
||||||
* [#76](https://github.com/Icinga/icinga-powershell-framework/issues/76) Adds support to test for required .NET Framework Version 4.6.0 or above before trying to install the Icinga Agent
|
* [#76](https://github.com/Icinga/icinga-powershell-framework/issues/76) Adds support to test for required .NET Framework Version 4.6.0 or above before trying to install the Icinga Agent
|
||||||
* [#87](https://github.com/Icinga/icinga-powershell-framework/issues/87) Adds wrapper command to test new code or functionality of Framework and/or plugins
|
* [#87](https://github.com/Icinga/icinga-powershell-framework/issues/87) Adds wrapper command to test new code or functionality of Framework and/or plugins
|
||||||
|
* [#88](https://github.com/Icinga/icinga-powershell-framework/issues/88) Adds Start/Stop timer functionality for performance analysis
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,13 @@ function Use-Icinga()
|
||||||
$global:IcingaThreads = [hashtable]::Synchronized(@{});
|
$global:IcingaThreads = [hashtable]::Synchronized(@{});
|
||||||
$global:IcingaThreadContent = [hashtable]::Synchronized(@{});
|
$global:IcingaThreadContent = [hashtable]::Synchronized(@{});
|
||||||
$global:IcingaThreadPool = [hashtable]::Synchronized(@{});
|
$global:IcingaThreadPool = [hashtable]::Synchronized(@{});
|
||||||
|
$global:IcingaTimers = [hashtable]::Synchronized(@{});
|
||||||
$global:IcingaDaemonData = [hashtable]::Synchronized(
|
$global:IcingaDaemonData = [hashtable]::Synchronized(
|
||||||
@{
|
@{
|
||||||
'IcingaThreads' = $global:IcingaThreads;
|
'IcingaThreads' = $global:IcingaThreads;
|
||||||
'IcingaThreadContent' = $global:IcingaThreadContent;
|
'IcingaThreadContent' = $global:IcingaThreadContent;
|
||||||
'IcingaThreadPool' = $global:IcingaThreadPool;
|
'IcingaThreadPool' = $global:IcingaThreadPool;
|
||||||
|
'IcingaTimers' = $global:IcingaTimers;
|
||||||
'FrameworkRunningAsDaemon' = $Daemon;
|
'FrameworkRunningAsDaemon' = $Daemon;
|
||||||
'DebugMode' = $DebugMode;
|
'DebugMode' = $DebugMode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
lib/core/framework/Get-IcingaTimer.psm1
Normal file
35
lib/core/framework/Get-IcingaTimer.psm1
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Fetches a Stopwatch system object by a given name if initialised with Start-IcingaTimer
|
||||||
|
.DESCRIPTION
|
||||||
|
Fetches a Stopwatch system object by a given name if initialised with Start-IcingaTimer
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Fetches a Stopwatch system object by a given name if initialised with Start-IcingaTimer
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Get-IcingaTimer;
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Get-IcingaTimer -Name 'My Test Timer';
|
||||||
|
.PARAMETER Name
|
||||||
|
The name of a custom identifier to run mutliple timers at once
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.OUTPUTS
|
||||||
|
System.Diagnostics.Stopwatch
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Get-IcingaTimer()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Name = 'DefaultTimer'
|
||||||
|
);
|
||||||
|
|
||||||
|
$TimerData = Get-IcingaHashtableItem -Key $Name -Hashtable $global:IcingaDaemonData.IcingaTimers;
|
||||||
|
|
||||||
|
if ($null -eq $TimerData) {
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $TimerData.Timer;
|
||||||
|
}
|
||||||
39
lib/core/framework/Show-IcingaTimer.psm1
Normal file
39
lib/core/framework/Show-IcingaTimer.psm1
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Returns the spent time since Start-IcingaTimer was executed in seconds for
|
||||||
|
a specific timer name
|
||||||
|
.DESCRIPTION
|
||||||
|
Returns the spent time since Start-IcingaTimer was executed in seconds for
|
||||||
|
a specific timer name
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Returns the spent time since Start-IcingaTimer was executed in seconds for
|
||||||
|
a specific timer name
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Show-IcingaTimer;
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Show-IcingaTimer -Name 'My Test Timer';
|
||||||
|
.PARAMETER Name
|
||||||
|
The name of a custom identifier to run mutliple timers at once
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.OUTPUTS
|
||||||
|
Single
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Show-IcingaTimer()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Name = 'DefaultTimer'
|
||||||
|
);
|
||||||
|
|
||||||
|
$TimerObject = Get-IcingaTimer -Name $Name;
|
||||||
|
|
||||||
|
if ($null -eq $TimerObject) {
|
||||||
|
Write-IcingaConsoleNotice 'A timer with the name "{0}" does not exist' -Objects $Name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $TimerObject.Elapsed.TotalSeconds;
|
||||||
|
}
|
||||||
45
lib/core/framework/Start-IcingaTimer.psm1
Normal file
45
lib/core/framework/Start-IcingaTimer.psm1
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Start a new timer for a given name and stores it within the $globals section
|
||||||
|
of the Icinga PowerShell Framework
|
||||||
|
.DESCRIPTION
|
||||||
|
Start a new timer for a given name and stores it within the $globals section
|
||||||
|
of the Icinga PowerShell Framework
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Start a new timer for a given name and stores it within the $globals section
|
||||||
|
of the Icinga PowerShell Framework
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Start-IcingaTimer;
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Start-IcingaTimer -Name 'My Test Timer';
|
||||||
|
.PARAMETER Name
|
||||||
|
The name of a custom identifier to run mutliple timers at once
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Start-IcingaTimer()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Name = 'DefaultTimer'
|
||||||
|
);
|
||||||
|
|
||||||
|
if ((Test-IcingaTimer)) {
|
||||||
|
Write-IcingaConsoleNotice 'The timer with the name "{0}" is already active' -Objects $Name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load the library first
|
||||||
|
[System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics");
|
||||||
|
$TimerObject = New-Object System.Diagnostics.Stopwatch;
|
||||||
|
$TimerObject.Start();
|
||||||
|
|
||||||
|
Add-IcingaHashtableItem -Key $Name -Value ([hashtable]::Synchronized(
|
||||||
|
@{
|
||||||
|
'Active' = $TRUE;
|
||||||
|
'Timer' = $TimerObject;
|
||||||
|
}
|
||||||
|
)) -Hashtable $global:IcingaDaemonData.IcingaTimers -Override | Out-Null;
|
||||||
|
}
|
||||||
44
lib/core/framework/Stop-IcingaTimer.psm1
Normal file
44
lib/core/framework/Stop-IcingaTimer.psm1
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Stops a timer object started with Start-IcingaTimer for a specific
|
||||||
|
named timer
|
||||||
|
.DESCRIPTION
|
||||||
|
Stops a timer object started with Start-IcingaTimer for a specific
|
||||||
|
named timer
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Stops a timer object started with Start-IcingaTimer for a specific
|
||||||
|
named timer
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Stop-IcingaTimer;
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Stop-IcingaTimer -Name 'My Test Timer';
|
||||||
|
.PARAMETER Name
|
||||||
|
The name of a custom identifier to run mutliple timers at once
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Stop-IcingaTimer()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Name = 'DefaultTimer'
|
||||||
|
);
|
||||||
|
|
||||||
|
$TimerObject = Get-IcingaTimer -Name $Name;
|
||||||
|
|
||||||
|
if ($null -eq $TimerObject) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($TimerObject.IsRunning) {
|
||||||
|
$TimerObject.Stop();
|
||||||
|
}
|
||||||
|
Add-IcingaHashtableItem -Key $Name -Value ([hashtable]::Synchronized(
|
||||||
|
@{
|
||||||
|
'Active' = $FALSE;
|
||||||
|
'Timer' = $TimerObject;
|
||||||
|
}
|
||||||
|
)) -Hashtable $global:IcingaDaemonData.IcingaTimers -Override | Out-Null;
|
||||||
|
}
|
||||||
35
lib/core/framework/Test-IcingaTimer.psm1
Normal file
35
lib/core/framework/Test-IcingaTimer.psm1
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Tests if a specific timer object is already present and started with Start-IcingaTimer
|
||||||
|
.DESCRIPTION
|
||||||
|
Tests if a specific timer object is already present and started with Start-IcingaTimer
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Tests if a specific timer object is already present and started with Start-IcingaTimer
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Test-IcingaTimer;
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Test-IcingaTimer -Name 'My Test Timer';
|
||||||
|
.PARAMETER Name
|
||||||
|
The name of a custom identifier to run mutliple timers at once
|
||||||
|
.INPUTS
|
||||||
|
System.String
|
||||||
|
.OUTPUTS
|
||||||
|
Boolean
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Test-IcingaTimer()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$Name = 'DefaultTimer'
|
||||||
|
);
|
||||||
|
|
||||||
|
$TimerData = Get-IcingaHashtableItem -Key $Name -Hashtable $global:IcingaDaemonData.IcingaTimers;
|
||||||
|
|
||||||
|
if ($null -eq $TimerData) {
|
||||||
|
return $FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $TimerData.Active;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue