mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Adds new Cmdlet Show-IcingaPerformanceCounterInstances
This commit is contained in:
parent
e3cd82feb3
commit
5a064078b2
2 changed files with 62 additions and 0 deletions
|
|
@ -15,6 +15,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
|
||||
* [#80](https://github.com/Icinga/icinga-powershell-framework/issues/80) Adds wrapper function `Get-IcingaWindowsInformation` for WMI and CIM calls to properly handle config/permission errors
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Adds new Cmdlet `Show-IcingaPerformanceCounterInstances` to display all avaiable instances for Performance Counters
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* [#78](https://github.com/Icinga/icinga-powershell-framework/issues/78) Fix Icinga Agent package fetching for x86 architecture
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Displays all available instances for a provided Performance Counter
|
||||
.DESCRIPTION
|
||||
Displays all available instances for a provided Performance Counter
|
||||
.FUNCTIONALITY
|
||||
Displays all available instances for a provided Performance Counter
|
||||
.PARAMETER Counter
|
||||
The name of the Performance Counter to fetch data for
|
||||
.EXAMPLE
|
||||
PS>Show-IcingaPerformanceCounterInstances -Counter '\Processor(*)\% processor time';
|
||||
|
||||
Name Value
|
||||
---- -----
|
||||
_Total \Processor(_Total)\% processor time
|
||||
0 \Processor(0)\% processor time
|
||||
1 \Processor(1)\% processor time
|
||||
2 \Processor(2)\% processor time
|
||||
3 \Processor(3)\% processor time
|
||||
...
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Show-IcingaPerformanceCounterInstances()
|
||||
{
|
||||
param (
|
||||
[string]$Counter
|
||||
);
|
||||
|
||||
[hashtable]$Instances = @{};
|
||||
|
||||
if ([string]::IsNullOrEmpty($Counter)) {
|
||||
Write-IcingaConsoleError 'Please enter a Performance Counter';
|
||||
return;
|
||||
}
|
||||
|
||||
$PerfCounter = New-IcingaPerformanceCounter -Counter $Counter -SkipWait $TRUE;
|
||||
|
||||
foreach ($entry in $PerfCounter.Counters) {
|
||||
$Instances.Add(
|
||||
$entry.Instance,
|
||||
($Counter.Replace('(*)', ([string]::Format('({0})', $entry.Instance))))
|
||||
);
|
||||
}
|
||||
|
||||
if ($Instances.Count -eq 0) {
|
||||
Write-IcingaConsoleNotice `
|
||||
-Message 'No instances were found for Performance Counter "{0}". Please ensure the provided counter has instances and you are using "*" for the instance name.' `
|
||||
-Objects $Counter;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
$Instances.GetEnumerator() | Sort-Object Name
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue