PureArrayDashboardIOPSData (Resource)

Element properties:

TypeResource
File NamePureArrayDashboardIOPSData.ps1
AccessibilityInternal

Source Code:

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

File Content: PureArrayDashboardIOPSData.ps1

$ScriptName = "PureArrayDashboardIOPSData.ps1"


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

LoadOperationsManagerModule $ScriptName

$whoami = whoami
$momapi = New-Object -comObject "Mom.ScriptAPI"
Log $ScriptName $GLOBAL:INFO_LEVEL "Starting script. Running as ($whoami)"
LoadPowerShellSDK $ScriptName

# Function to add the DB Free Space to the data object.
# Parameters:
# dataObject - The data object that is being modified.
# PureArray instance - The database instance. This is used to get the performance data.
# criteria - Criteria to use for retrieving the performance data.
# startTime - The starting time of the performance data to collect.
# endTime - The ending time of the performance data to collect.
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
}
if ($counter -eq 0) {
Log $ScriptName $GLOBAL:WARNING_LEVEL "No perf data for $counterName"
return $null
}
$perfValue = $sum / $counter
$perfValue = [Math]::Round($perfValue * 0.001, 4)
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Value for counter $counterName is $perfValue"
$dataObject[$counterName] = [string]($perfValue) + ' K/s'
return $perfValue
}

$class = Get-SCOMClass -Name PureStorage.FlashArray.PureArray
$pureArrays = Get-SCOMClassInstance -Class $class

# The perf APIs require a start and end time
# In this case, we specify current time as end time and 1 hour ago as start time.
$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.
$inputPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Reads per Second'")
$inputPerfValue = SetAndReturnPerfCounterLastValue $dataObject $pureArray $inputPerfCriteria 'Reads per Second' $startTime $endTime
$outputPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Writes per Second'")
$outputPerfValue = SetAndReturnPerfCounterLastValue $dataObject $pureArray $outputPerfCriteria 'Writes per Second' $startTime $endTime

$totalPerfCriteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='Total IOPs'")
$totalPerfValue = SetAndReturnPerfCounterLastValue $dataObject $pureArray $totalPerfCriteria 'Total IOPs' $startTime $endTime

$ScriptContext.ReturnCollection.Add($dataObject)
}