PureArrayDashboardSpaceMetricsData (Resource)

Element properties:

TypeResource
File NamePureArrayDashboardSpaceMetricsData.ps1
AccessibilityInternal

Source Code:

<Resource FileName="PureArrayDashboardSpaceMetricsData.ps1" ID="PureArrayDashboardSpaceMetricsData" Accessibility="Internal" HasNullStream="false"/>

File Content: PureArrayDashboardSpaceMetricsData.ps1

$ScriptName = "PureArrayDashboardSpaceMetricsData.ps1"


# Reference shared code
$SharedLibKey = Get-ItemProperty "HKLM:\SOFTWARE\PureStorage\SCOM\SharedLibPath"
$SharedLibPath = $SharedLibKey.'(default)'
. "$SharedLibPath"

LoadOperationsManagerModule $ScriptName

$whoami = whoami
Log $ScriptName $GLOBAL:INFO_LEVEL "Starting script. Running as ($whoami)"
LoadPowerShellSDK $ScriptName

function GetPerfCounterLastValue($dataObject, $instance, $criteria, $startTime, $endTime)
{
$performanceDataCollection = $instance.GetMonitoringPerformanceData($criteria)
Log $ScriptName $GLOBAL:VERBOSE_LEVEL $performanceDataCollection
if ($performanceDataCollection.Count -lt 1) {
Log $ScriptName $GLOBAL:WARNING_LEVEL "No perf data for $counterName"
return $null
}
$performanceData = $performanceDataCollection[0]
$dataCollection = $performanceData.GetValues($startTime, $endTime)
if ($dataCollection.Count -lt 1) { return $null }
$lastDataValue = $dataCollection[$dataCollection.Count - 1].SampleValue
return $lastDataValue
}

$class = Get-SCOMClass -Name PureStorage.FlashArray.PureArray
$pureArrays = Get-SCOMClassInstance -Class $class
$endTime = [DateTime]::UtcNow
$timeDiff = [TimeSpan]::FromHours(1)
$startTime = $endTime - $timeDiff


foreach ($pureArray in $pureArrays)
{
$dataObject = $ScriptContext.CreateFromObject($pureArray, "Id=Id,DisplayName=DisplayName", "ArrayName=ArrayName")
$totalPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Capacity'")
$capacity = GetPerfCounterLastValue $dataObject $pureArray $totalPerfCriteria $startTime $endTime
$totalPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Used Space'")
$usedSpace = GetPerfCounterLastValue $dataObject $pureArray $totalPerfCriteria $startTime $endTime
$capacity = $capacity / 1GB
$usedSpace = $usedSpace / 1GB
$freeSpace = $capacity - $usedSpace
if ($capacity -eq 0) {
$percentage = 0
} else {
$percentage = ($usedSpace / $capacity) * 100
}
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "dataobject: $dataObject"
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "capacity: $capacity"
if ($capacity -ge 1024) {
$dataObject['Capacity'] = [string]([Math]::Round($capacity / 1024, 2)) + ' T'
} else {
$testVal = [Math]::Round($capacity, 2) + ' G'
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "capacity after: $testVal"
$dataObject['Capacity'] = [string][Math]::Round($capacity, 2) + ' G'
}
if ($usedSpace -ge 1024) {
$dataObject['UsedSpace'] = [string]([Math]::Round($usedSpace / 1024, 2)) + ' T'
} else {
$dataObject['UsedSpace'] = [string][Math]::Round($usedSpace, 2) + ' G'
}
if ($freeSpace -ge 1024) {
$dataObject['FreeSpace'] = [string]([Math]::Round($freeSpace / 1024, 2)) + ' T'
} else {
$dataObject['FreeSpace'] = [string][Math]::Round($freeSpace, 2) + ' G'
}
$dataObject['Percentage'] = [string]([Math]::Round($percentage, 2)) + '%'
$ScriptContext.ReturnCollection.Add($dataObject)
}