Modules/stats.psm1

function Get-DDStats {
    [CmdletBinding()]
    param ( 
       [CmdletBinding()]
       [Parameter(Mandatory = $true, ParameterSetName = 'file-systems')]
       [switch]$filesys,
       [Parameter(Mandatory = $true, ParameterSetName = 'file-systems')]
       [ValidateSet('active','archive','cloud','total')]
       [string]$tier,
       [Parameter(Mandatory = $false, ParameterSetName = 'file-systems')]
       [switch]$need_delta,                
       [Parameter(Mandatory = $true, ParameterSetName = 'repl')]
       [switch]$repl,
       [Parameter(Mandatory = $true, ParameterSetName = 'capacity')]
       [switch]$capacity,        
       [Parameter(Mandatory = $false, ParameterSetName = 'default')]
       [Parameter(Mandatory = $false, ParameterSetName = 'file-systems')]
       [Parameter(Mandatory = $false, ParameterSetName = 'repl')]
       [Parameter(Mandatory = $false, ParameterSetName = 'capacity')]
 
       [string]
       $SYSTEM_ID = $Global:DD_UUID,
       $body = @{}
    )
    begin {
       $Response = @()
       $METHOD = "GET"
    }
    process {
       $apiver = "rest/v2.0"
       switch ($PsCmdlet.ParameterSetName) {
          'default' {
             $uri = "dd-systems/$($SYSTEM_ID)/stats"
          }
          default {
             $uri = "dd-systems/$($SYSTEM_ID)/stats/$($PsCmdlet.ParameterSetName)"
          }
          'file-systems'{
            $apiver = "rest/v1.0"
            $body.Add('tier',$tier)
            $body.Add('need_delta',$need_delta.IsPresent)
            # $body = $body | ConvertTo-Json
            $uri = "dd-systems/$($SYSTEM_ID)/stats/$($PsCmdlet.ParameterSetName)"

          }                    
       }
       write-verbose ($body | Out-String)
       $parameters = @{
          uri           = $uri          
          apiver        = $apiver
          Method        = $METHOD
          body          = $body
          RequestMethod = "REST"
          Verbose       = $PSBoundParameters['Verbose'] -eq $true
       }      
       try {
          $Response += Invoke-DDapirequest @Parameters
       }
       catch {
          Get-DDWebException  -ExceptionMessage $_
          break
       }
       write-verbose ($response | Out-String)
    }
    end {    
       switch ($PsCmdlet.ParameterSetName) {
          'capacity' {
             $response.stats_capacity | Select-Object -Property *,@{N="collection_time";E={(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($_.collection_epoch))}} -ExcludeProperty link,tier_capacity_usage -ExpandProperty tier_capacity_usage
          }
          'file-systems' {
            $response #.stats_capacity | Select-Object -Property *,@{N="collection_time";E={(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($_.collection_epoch))}} -ExcludeProperty link,tier_capacity_usage -ExpandProperty tier_capacity_usage
         }          
          default   
          {
             $response[-1].stats | Select-Object -ExcludeProperty link -ExpandProperty retention_info
          }      
       } 
       
    }
 }