Type de module pour la bande passante de carte réseau utilisée

Microsoft.Windows.Server.10.0.NetworkAdapter.BandwidthUsed.ModuleType (DataSourceModuleType)

Type de module de source de données pour les compteurs de bande passante de carte réseau utilisée.

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
EmptyCondition ConditionDetection System.ExpressionFilter Default
InstanceFilter ConditionDetection System.ExpressionFilter Default
PerfMapper ConditionDetection System.Performance.DataGenericMapper Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Intervalint$Config/IntervalSeconds$Intervalle en secondesÀ quelle fréquence (en secondes) la valeur doit être échantillonnée.

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.10.0.NetworkAdapter.BandwidthUsed.ModuleType" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IsDiscoverDisabled" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IsUseMacAddress" type="xsd:boolean"/>
<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="InstanceName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CounterName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Interval" 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.NetworkAdapter.BandwidthUsed.ModuleType.ps1</ScriptName>
<PSparam>param ($sTargetComputer, $IsUseMacAddress)</PSparam>
<ScriptBody><Script>
#Copyright (c) Microsoft Corporation. All rights reserved.

# Parameters that should be passed to this script
# 0 Computer name this rule is running against
# 1 Use MacAddress for discovery (true), otherwise NetConnectionID

$CN_PercentBandwidthUsedRead = "PercentBandwidthUsedRead"
$CN_PercentBandwidthUsedWrite = "PercentBandwidthUsedWrite"
$CN_PercentBandwidthUsedTotal = "PercentBandwidthUsedTotal"
$WIN_SRV_VNEXT_OSVer = "6.3"

Function Main()
{
# Win32_NetworkAdapter is deprecated and not returning results on NanoServer
# Need to use MSFT_NetAdapter
$bIsUseMacAddress = Convert-ToBoolean -sBool $IsUseMacAddress
$bIsModuleLoaded = Load-Module -ModuleName "NetAdapter"
$bHasItems = $false

if ($false -eq $bIsModuleLoaded)
{
$netAdapters = $null
}
else
{
# -Physical Corresponds to "ServiceName &lt;&gt; 'VMSMP'"
$netAdapters = Get-NetAdapter -Physical | Where `
{($bIsUseMacAddress -eq $true -and $_.MacAddress -ne $null -and $false -eq [string]::IsNullOrEmpty($_.Name)) `
-or ($bIsUseMacAddress -eq $false -and $false -eq [string]::IsNullOrEmpty($_.Name))}
}

foreach ($netAdapter in $netAdapters)
{
$bIsDisabled = $netAdapter.MediaConnectState -eq "2"
$sPerfMonInstanceName = GetPerfmonInstance $netAdapter.InterfaceDescription
$sQuery = "Win32_PerfFormattedData_Tcpip_NetworkAdapter Where Name ='" + $sPerfMonInstanceName + "'"

$WMISet2 = WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" $sQuery

if ($null -ne $WMISet2 -and $null -eq $WMISet2.Count)
{
$nCurrentBandwidth = $WMISet2.CurrentBandwidth
$nBytesSentPersec = $WMISet2.BytesSentPersec
$nBytesReceivedPersec = $WMISet2.BytesReceivedPersec
$nBytesTotalPersec = $WMISet2.BytesTotalPersec

if ($nCurrentBandwidth -ne $null -and $nBytesSentPersec -ne $null -and $nBytesReceivedPersec -ne $null -and $nBytesTotalPersec -ne $null)
{
$Counters = @{}
$Counters[$CN_PercentBandwidthUsedRead] = CalculatePercent $nBytesReceivedPersec ($nCurrentBandwidth/8) # Divide CurrentBandwidth by 8 to convert it from bits to bytes.
$Counters[$CN_PercentBandwidthUsedWrite] = CalculatePercent $nBytesSentPersec ($nCurrentBandwidth/8)
$Counters[$CN_PercentBandwidthUsedTotal] = CalculatePercent $nBytesTotalPersec ($nCurrentBandwidth/8)
$bHasItems = $true
foreach ($oCounter in $Counters.Keys)
{
$oBag = $momAPI.CreateTypedPropertyBag(2)
$oBag.AddValue("IsNotEmpty", $bHasItems)
$oBag.AddValue("IsDisabled", $bIsDisabled)
$oBag.AddValue("PerfInstance", $sPerfMonInstanceName)
$oBag.AddValue("PerfCounter", $oCounter)
$oBag.AddValue("PerfValue", $Counters.Item($oCounter))
$oBag
}
}
}

}

Add-EmptyBag -bHasItems $bHasItems

}

Function Add-EmptyBag([bool]$bHasItems)
{
if ($true -eq $bHasItems)
{
return
}

$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$oEmptyBag = $momAPI.CreateTypedPropertyBag(2)

$oEmptyBag.AddValue("IsNotEmpty", $bHasItems)
$oEmptyBag.AddValue("PerfInstance", "")
$oEmptyBag.AddValue("PerfCounter", "")
$oEmptyBag.AddValue("PerfValue", "")
$oEmptyBag
}

Function CalculatePercent($nDivident, $nDivider)
{
$nResult = 0
If (($nDivider -ne 0) -and ($nDivident -ne 0))
{
$nResult = $nDivident/$nDivider*100
}
return $nResult
}

Function GetPerfmonInstance($sName)
{
$sName = $sName -replace("\(","[")
$sName = $sName -replace("\)","]")
$sName = $sName -replace("/","_")
$sName = $sName -replace("#","_")
return $sName
}



Main</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sTargetComputer</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
<Parameter>
<Name>IsUseMacAddress</Name>
<Value>$Config/IsUseMacAddress$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="PerfMapper" TypeID="SystemPerf!System.Performance.DataGenericMapper">
<ObjectName>Network Adapter</ObjectName>
<CounterName>$Data/Property[@Name='PerfCounter']$</CounterName>
<InstanceName>$Data/Property[@Name='PerfInstance']$</InstanceName>
<Value>$Data/Property[@Name='PerfValue']$</Value>
</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/InstanceName$</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>
<ConditionDetection ID="EmptyCondition" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='IsNotEmpty']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<Or>
<Expression>
<SimpleExpression>
<ValueExpression>
<Value Type="Boolean">$Config/IsDiscoverDisabled$</Value>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<Value Type="Boolean">$Config/IsDiscoverDisabled$</Value>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">false</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='IsDisabled']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">false</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</Or>
</Expression>
</And>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="PerfMapper">
<Node ID="InstanceFilter">
<Node ID="EmptyCondition">
<Node ID="PA">
<Node ID="Scheduler"/>
</Node>
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>SystemPerf!System.Performance.Data</OutputType>
</DataSourceModuleType>