Variables.ps1

#
# Logging
#
New-Variable -Name 'IN_MEMORY_LOGS' -Value ([System.Collections.ArrayList]::new()) -Option ReadOnly -Scope Script -Force
New-Variable -Name 'CONSOLE_LOG_LEVEL' -Value 'INFO' -Option ReadOnly -Scope Script -Force
#
# Spools
#
New-Variable -Name 'SPOOL_FOLDER_NAME' -Value 'Spool' -Option ReadOnly -Scope Script -Force
New-Variable -Name "SPOOL_MAX_FILE_COUNT" -Value 100 -Option ReadOnly -Scope Script -Force

#
# Virtual Machines
#
New-Variable -Name 'STORAGE_FOLDER_NAME' -Value 'Storage' -Option ReadOnly -Scope Script -Force
New-Variable -Name 'VM_ENRICHMENT_BATCH_SIZE' -Value 1000 -Option ReadOnly -Scope Script -Force
New-Variable -Name 'VM_CACHE_EXPIRATION' -Value 'PT1H' -Option ReadOnly -Scope Script -Force

#
# Time window constants
#
New-Variable -Name 'MAX_MINUTES_READ' -Value 20 -Option ReadOnly -Scope Script -Force

#
# Nutanix Prism Central v4 API tuning
#

# Event duration. 20s, not the 30s product target, because the Nexthink hypervisor-processor backend
# hardcodes INPUT_DURATION_BUCKET_SIZE_SECONDS=20 and silently drops any other duration. It also
# only accepts whole minutes per host (3 events starting at :00, 20s apart) and rejects the entire
# host entry otherwise.
New-Variable -Name 'NUTANIX_STATS_SAMPLING_INTERVAL_SECONDS' -Value 20 -Option ReadOnly -Scope Script -Force

# Prism Central's native stats resolution. It returns 30s-spaced points for any $samplingInterval
# below 30 (lab-validated with 10, 20, and 30), so the 30s points of each complete minute are
# resampled onto the 20s buckets: bucket i takes the source points at the listed second offsets and
# averages them when there are two. Bucket [20,40) straddles both source points equally.
New-Variable -Name 'NUTANIX_PC_STATS_RESOLUTION_SECONDS' -Value 30 -Option ReadOnly -Scope Script -Force
New-Variable -Name 'NUTANIX_BUCKET_SOURCE_OFFSETS' -Value @(@(0), @(0, 30), @(30)) -Option ReadOnly -Scope Script -Force

# Retry budget for transient Prism Central failures.
New-Variable -Name 'NUTANIX_API_MAX_RETRIES' -Value 3 -Option ReadOnly -Scope Script -Force

# v4 list endpoints accept $limit 1-100 and default to 50 when omitted; always page at the maximum.
New-Variable -Name 'NUTANIX_STATS_PAGE_LIMIT' -Value 100 -Option ReadOnly -Scope Script -Force

# Outbound request-start ceiling, well below the smallest documented Prism Central rate limit
# (30 req/s for an X-Small PC). Prism Central answers HTTP 429 above its limit.
New-Variable -Name 'NUTANIX_API_MAX_REQUESTS_PER_SECOND' -Value 10 -Option ReadOnly -Scope Script -Force
New-Variable -Name 'NUTANIX_HOST_STATS_MAX_CONCURRENCY' -Value 5 -Option ReadOnly -Scope Script -Force

# clustermgmt/v4.0/config/clusters. clusterFunction tells the Prism Central's own registration
# (PRISM_CENTRAL, no AHV hosts) apart from the AOS clusters it manages.
New-Variable -Name 'NUTANIX_CLUSTER_SELECT' -Value 'extId,name,config/clusterFunction' -Option ReadOnly -Scope Script -Force
New-Variable -Name 'NUTANIX_CLUSTER_FUNCTION_SKIP' -Value @('PRISM_CENTRAL') -Option ReadOnly -Scope Script -Force

# clustermgmt/v4.0/stats/clusters/{clusterExtId}/hosts/{hostExtId}. The series are top-level
# properties of the HostStats object, so $select takes bare names (lab-validated: a 'stats/' prefix
# is rejected with CLU-10007). The controller* series are the CVM storage-path counters, the same
# layer Prism Element v2 reported for read/write bandwidth and average I/O latency.
New-Variable -Name 'NUTANIX_HOST_STATS_SELECT' -Value (@(
    'hypervisorCpuUsagePpm',
    'aggregateHypervisorMemoryUsagePpm',
    'memoryCapacityBytes',
    'controllerReadIoBandwidthKbps',
    'controllerWriteIoBandwidthKbps',
    'controllerAvgIoLatencyUsecs'
) -join ',') -Option ReadOnly -Scope Script -Force

# Host series that mark a real performance bucket. memoryCapacityBytes is deliberately absent: Prism
# Central returns it as one point stamped with the last capacity change, not per bucket.
New-Variable -Name 'NUTANIX_HOST_EVENT_SERIES' -Value @(
    'hypervisorCpuUsagePpm',
    'aggregateHypervisorMemoryUsagePpm',
    'controllerReadIoBandwidthKbps',
    'controllerWriteIoBandwidthKbps',
    'controllerAvgIoLatencyUsecs'
) -Option ReadOnly -Scope Script -Force

# vmm/v4.0/ahv/config/vms. Leave empty to request the full VM object.
New-Variable -Name 'NUTANIX_VM_CONFIG_SELECT' -Value (@(
    'extId',
    'name',
    'host',
    'cluster',
    'powerState',
    'numSockets',
    'numCoresPerSocket',
    'numThreadsPerCore',
    'memorySizeBytes',
    'guestTools',
    'storageConfig'
) -join ',') -Option ReadOnly -Scope Script -Force

# vmm/v4.0/ahv/stats/vms down-sampling operator; the list endpoint requires one.
New-Variable -Name 'NUTANIX_VM_STATS_TYPE' -Value 'AVG' -Option ReadOnly -Scope Script -Force

# vmm/v4.0/ahv/stats/vms. Tuples live under 'stats', so these take the 'stats/' prefix and must
# include the timestamp. The endpoint rejects an empty $select.
New-Variable -Name 'NUTANIX_VM_STATS_SELECT' -Value (@(
    'extId',
    'stats/timestamp',
    'stats/hypervisorCpuReadyTimePpm',
    'stats/hypervisorSwapInRateKbps',
    'stats/hypervisorSwapOutRateKbps'
) -join ',') -Option ReadOnly -Scope Script -Force