Public/Get-DMPortPerformance.ps1
|
function Get-DMPortPerformance { <# .SYNOPSIS Retrieves realtime performance samples for OceanStor ports. .DESCRIPTION Thin wrapper around Get-DMPerformance for the port object types. Accepts one or more port objects via pipeline (e.g. from Get-DMPortFc, Get-DMPortEth, or Get-DMPortBond) plus a mandatory -PortType selecting which object type the batch call targets. Batches all piped IDs into a single performance_data call per sample -- required because the endpoint cannot be invoked concurrently. FCoE and InfiniBand ports are documented object types in the REST API, but this module has no corresponding getter/class for them yet, so -PortType only supports FC/ETH/Bond. .PARAMETER WebSession Optional parameter to define the session to be use on the REST call. If not defined, the module's cached $script:CurrentOceanstorSession session will be used .PARAMETER PortType The port type being piped in. One of FC, ETH, Bond. .PARAMETER InputObject One or more port objects (OceanStorPortFC, OceanStorPortETH, or OceanStorPortBond, matching -PortType), pipeline-able. .PARAMETER Metric One or more friendly metric names (see Get-DMPerformanceIndicatorMap). Defaults to Get-DMPerformance's own default set when omitted. .PARAMETER SampleCount Number of samples to take. Defaults to 1. .PARAMETER IntervalSeconds Delay between samples when SampleCount is greater than 1. Defaults to 5. .INPUTS OceanStorPortFC, OceanStorPortETH, OceanStorPortBond .OUTPUTS System.Collections.ArrayList .EXAMPLE PS> Get-DMPortFc | Get-DMPortPerformance -PortType FC .EXAMPLE PS> Get-DMPortBond | Get-DMPortPerformance -PortType Bond -Metric TotalIOPS .NOTES Filename: Get-DMPortPerformance.ps1 #> [CmdletBinding()] [OutputType([System.Collections.ArrayList])] param( [Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $false)] [pscustomobject]$WebSession, [Parameter(Mandatory = $true)] [ValidateSet('FC', 'ETH', 'Bond')] [string]$PortType, [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object[]]$InputObject, [Parameter(Mandatory = $false)] [ArgumentCompleter({ param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) (Get-DMPerformanceIndicatorMap).Keys | Where-Object { $_ -like "$wordToComplete*" } })] [ValidateScript({ $validNames = (Get-DMPerformanceIndicatorMap).Keys foreach ($metricName in $_) { if ($metricName -notin $validNames) { throw "Unknown performance metric '$metricName'. Valid metrics: $($validNames -join ', ')" } } return $true })] [string[]]$Metric, [Parameter(Mandatory = $false)] [int]$SampleCount = 1, [Parameter(Mandatory = $false)] [int]$IntervalSeconds = 5 ) begin { $session = if ($WebSession) { $WebSession } else { $script:CurrentOceanstorSession } $ids = [System.Collections.Generic.List[string]]::new() $objectType = switch ($PortType) { 'FC' { 'FCPort' } 'ETH' { 'EthernetPort' } 'Bond' { 'BondPort' } } } process { foreach ($obj in $InputObject) { $ids.Add($obj.Id) } } end { if ($ids.Count -eq 0) { return } $params = @{ WebSession = $session; ObjectType = $objectType; ObjectId = @($ids) } if ($PSBoundParameters.ContainsKey('Metric')) { $params.Metric = $Metric } for ($s = 0; $s -lt $SampleCount; $s++) { Get-DMPerformance @params if ($s -lt ($SampleCount - 1)) { Start-Sleep -Seconds $IntervalSeconds } } } } |