icinga-powershell-framework/lib/core/framework/Show-IcingaTimer.psm1

62 lines
1.9 KiB
PowerShell
Raw Normal View History

<#
.SYNOPSIS
2021-12-09 11:42:06 -05:00
Returns the spent time since Start-IcingaTimer was executed in seconds for
a specific timer name
.DESCRIPTION
2021-12-09 11:42:06 -05:00
Returns the spent time since Start-IcingaTimer was executed in seconds for
a specific timer name
.FUNCTIONALITY
2021-12-09 11:42:06 -05:00
Returns the spent time since Start-IcingaTimer was executed in seconds for
a specific timer name
.EXAMPLE
2021-12-09 11:42:06 -05:00
PS>Show-IcingaTimer;
.EXAMPLE
2021-12-09 11:42:06 -05:00
PS>Show-IcingaTimer -Name 'My Test Timer';
.PARAMETER Name
2021-12-09 11:42:06 -05:00
The name of a custom identifier to run multiple timers at once
.INPUTS
2021-12-09 11:42:06 -05:00
System.String
.OUTPUTS
2021-12-09 11:42:06 -05:00
Single
.LINK
2021-12-09 11:42:06 -05:00
https://github.com/Icinga/icinga-powershell-framework
#>
function Show-IcingaTimer()
{
param (
[string]$Name = 'DefaultTimer',
[switch]$ShowAll = $FALSE
);
$TimerObject = Get-IcingaTimer -Name $Name;
if (-Not $ShowAll) {
2021-12-09 11:42:06 -05:00
if ($null -eq $TimerObject) {
Write-IcingaConsoleNotice 'A timer with the name "{0}" does not exist' -Objects $Name;
return;
}
$TimerOutput = New-Object -TypeName PSObject;
$TimerOutput | Add-Member -MemberType NoteProperty -Name 'Timer Name' -Value $Name;
$TimerOutput | Add-Member -MemberType NoteProperty -Name 'Elapsed Seconds' -Value $TimerObject.Elapsed.TotalSeconds;
$TimerOutput | Format-Table -AutoSize;
} else {
2021-12-09 11:42:06 -05:00
$TimerObjects = Get-IcingaHashtableItem -Key 'Timers' -Hashtable $Global:Icinga.Private;
[array]$MultiOutput = @();
foreach ($TimerName in $TimerObjects.Keys) {
2021-12-09 11:42:06 -05:00
$TimerObject = $TimerObjects[$TimerName].Timer;
2021-12-09 11:42:06 -05:00
$TimerOutput = New-Object -TypeName PSObject;
$TimerOutput | Add-Member -MemberType NoteProperty -Name 'Timer Name' -Value $TimerName;
$TimerOutput | Add-Member -MemberType NoteProperty -Name 'Elapsed Seconds' -Value $TimerObject.Elapsed.TotalSeconds;
$MultiOutput += $TimerOutput;
}
$MultiOutput | Format-Table -AutoSize;
}
}