Windows Logical Disk State Data Source Module

Microsoft.Windows.Server.10.0.DiskState.DS.Moduletype (DataSourceModuleType)

Monitor the Logical Disk State on Windows Servers

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Performance.Data

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.Scheduler Default
PA ProbeAction Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe Default
EmptyCD ConditionDetection System.ExpressionFilter Default
InstanceFilter ConditionDetection System.ExpressionFilter Default
PerfMapper ConditionDetection System.Performance.DataGenericMapper Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval secondsHow frequently (in seconds) the value should be sampled.

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.10.0.DiskState.DS.Moduletype" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DiskLabel" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CounterName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime/>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe">
<ScriptName>Microsoft.Windows.Server.DiskState.ps1</ScriptName>
<PSparam>param ($TargetComputer)</PSparam>
<ScriptBody><Script>
#Copyright (c) Microsoft Corporation. All rights reserved.
#
# Parameters that should be passed to this script
# 0 Computer (FQDN)


$BYTES_IN_MB = 1048576 #=2^20

$LogicalObjectName = "System Logical Disk"
$GeneralObjectName = "Logical Disk"
$PrcFreeCounterName = "PercentFree"
$MbFreeCounterName = "MbFree"

Function Main()
{
$bBagIsNotEmpty = $false
$IsNotEmpty = $false
$IsNano = Is_NanoServer
$IsVolumeInfoSupported = Is_Win32_Volume_Supported $TargetComputer
$SystemDrive = Get_System_Drive $TargetComputer


$oVolumes = Get-Volumes -IsNano $IsNano -IsVolumeSupported $IsVolumeInfoSupported -TargetComputer $TargetComputer


foreach ($oVolume in $oVolumes)
{

$VolumeId = Get-VolumeId -IsNano $IsNano -IsVolumeSupported $IsVolumeInfoSupported -Volume $oVolume
if ($true -eq $IsNano)
{
$nFreeSpace = $oVolume.SizeRemaining
$nMaxSize = $oVolume.Size
}
else
{
$nFreeSpace = $oVolume.FreeSpace
if ($IsVolumeInfoSupported)
{
$nMaxSize = $oVolume.Capacity
}
else
{
$nMaxSize = $oVolume.Size
}
}


Create-PerfData -VolumeId $VolumeId -nMaxSize $nMaxSize -nFreeSpace $nFreeSpace -SystemDrive $SystemDrive -momAPI $momAPI -bBagIsNotEmpty ([ref]$IsNotEmpty)
if ($false -eq $bBagIsNotEmpty)
{
if ($true -eq $IsNotEmpty)
{
$bBagIsNotEmpty = $true
}
}

}

if ($false -eq $bBagIsNotEmpty)
{
$ErrorActionPreference="SilentlyContinue"
$error.Clear()
$oBag = $momAPI.CreatePropertyBag()
$oBag.AddValue("IsNotEmpty", "false")
$oBag
}

Unload-Module -ModuleName "Storage"
Unload-Module -ModuleName "CimCmdLets"
}

Function Create-PerfData([string]$VolumeId,$nMaxSize,$nFreeSpace,[string]$SystemDrive,$momAPI, [ref]$bBagIsNotEmpty)
{
$ErrorActionPreference="SilentlyContinue"
$error.Clear()

if ($null -eq $momAPI)
{
return
}

if ($nMaxSize -eq $null -or $nMaxSize -eq 0)
{
return
}

if ($nFreeSpace -eq $null)
{
$nFreeSpace = 0
}

$nPctFree = [math]::Round($nFreeSpace / $nMaxSize * 100, 2)
$nMBFree = [math]::Round($nFreeSpace / $BYTES_IN_MB, 0)
if ($VolumeId -ieq $SystemDrive)
{
$bIsSystemDrive = "true"
$sPerfObject = $LogicalObjectName
}
else
{
$bIsSystemDrive = "false"
$sPerfObject = $GeneralObjectName
}

$oBag = $momAPI.CreateTypedPropertyBag(2)
$oBag.AddValue("IsNotEmpty", "true")
$oBag.AddValue("PerfObject" , $sPerfObject)
$oBag.AddValue("PerfCounter" , $PrcFreeCounterName)
$oBag.AddValue("PerfInstance", $VolumeId)
$oBag.AddValue("PerfValue", [string]$nPctFree)

if ($error.Count -eq 0)
{
$oBag
$bBagIsNotEmpty.Value = $true
}

$error.Clear()
$oBag = $momAPI.CreateTypedPropertyBag(2)
$oBag.AddValue("IsNotEmpty", "true")
$oBag.AddValue("PerfObject" , $sPerfObject)
$oBag.AddValue("PerfCounter" , $MbFreeCounterName)
$oBag.AddValue("PerfInstance", $VolumeId)
$oBag.AddValue("PerfValue", [string]$nMBFree)

if ($error.Count -eq 0)
{
$oBag
$bBagIsNotEmpty.Value = $true
}
}


Main
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>TargetComputer</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="PerfMapper" TypeID="SystemPerf!System.Performance.DataGenericMapper">
<ObjectName>$Data/Property[@Name='PerfObject']$</ObjectName>
<CounterName>$Data/Property[@Name='PerfCounter']$</CounterName>
<InstanceName>$Data/Property[@Name='PerfInstance']$</InstanceName>
<Value>$Data/Property[@Name='PerfValue']$</Value>
</ConditionDetection>
<ConditionDetection ID="EmptyCD" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='IsNotEmpty']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="InstanceFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='PerfInstance']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/DiskLabel$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='PerfCounter']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/CounterName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="PerfMapper">
<Node ID="InstanceFilter">
<Node ID="EmptyCD">
<Node ID="PA">
<Node ID="Scheduler"/>
</Node>
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>SystemPerf!System.Performance.Data</OutputType>
</DataSourceModuleType>