PureArrayDashboardBandwidthData (Resource)

Element properties:

TypeResource
File NamePureArrayDashboardBandwidthData.ps1
AccessibilityInternal

Source Code:

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

File Content: PureArrayDashboardBandwidthData.ps1

$ScriptName = "PureArrayDashboardBandwidthData.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 SetAndReturnPerfCounterLastValue($dataObject, $instance, $criteria, $counterName, $startTime, $endTime)
{
$performanceDataCollection = $instance.GetMonitoringPerformanceData($criteria)
Log $ScriptName $GLOBAL:VERBOSE_LEVEL $performanceDataCollection
$valueReader = $performanceDataCollection.GetValueReader($startTime, $endTime)
$counter = 0
$sum = 0
while ($valueReader.Read()) {
$counter += 1
$sum += $valueReader.GetMonitoringPerformanceDataValue().SampleValue
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Sum is $sum"
}
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Counter: $sum"
if ($counter -eq 0) {
Log $ScriptName $GLOBAL:WARNING_LEVEL "No perf data for $counterName"
return $null
}
$avgDataValue = $sum / $counter
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Value for counter $counterName is $avgDataValue"
$perfData = $avgDataValue / 1024

if ($perfData -ge 1024) {
$dataObject[$counterName] = [string]([Math]::Round($perfData / 1024, 2)) + ' MB/s'
} else {
$dataObject[$counterName] = [string]([Math]::Round($perfData, 2)) + ' KB/s'
}
return $perfData
}

$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)
{
# Create a data object for the each database specifying the database object and the properties to include.
$dataObject = $ScriptContext.CreateFromObject($pureArray, "Id=Id,DisplayName=DisplayName", "ArrayName=ArrayName")
# Call function to add the performance data to the data object.
$readPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Read Bandwidth'")
$readPerfValue = SetAndReturnPerfCounterLastValue $dataObject $pureArray $readPerfCriteria 'Read Bandwidth' $startTime $endTime
$writePerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Write Bandwidth'")
$writePerfValue = SetAndReturnPerfCounterLastValue $dataObject $pureArray $writePerfCriteria 'Write Bandwidth' $startTime $endTime
$totalPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Total Bandwidth'")
$totalPerfValue = SetAndReturnPerfCounterLastValue $dataObject $pureArray $totalPerfCriteria 'Total Bandwidth' $startTime $endTime
$ScriptContext.ReturnCollection.Add($dataObject)
}