Microsoft.SystemCenter.VirtualMachineManager.Report.TimedPowerShell.VNicUsagePerformanceProvider (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Performance.Data

Member Modules:

ID Module Type TypeId RunAs 
DS1 DataSource Microsoft.SystemCenter.VirtualMachineManager.Report.TimedPowerShell.PerformanceProvider Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.VirtualMachineManager.Report.TimedPowerShell.VNicUsagePerformanceProvider" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.ParamListSchema</SchemaType>
<SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
<SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Parameters" type="NamedParametersType" minOccurs="0" maxOccurs="1"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS1" TypeID="Microsoft.SystemCenter.VirtualMachineManager.Report.TimedPowerShell.PerformanceProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ScriptName>GetAllVNicUsage</ScriptName>
<ScriptBody><Script>param($VMMServer, $domain, $username, $pass)

function ProducePerfPropertyBags
{
param($vnicSentPerf, $vnicRecvPerfMap)


if ($vnicSentPerf -ne $null)
{
foreach ($vnicPerf in $vnicSentPerf)
{
if ($vnicPerf.Name -ne $null)
{
$pBag = $oAPI.CreatePropertyBag()

$pBag.AddValue('InstanceName', $vnicPerf.Name);

$recvKBytes = if ($vnicRecvPerfMap.ContainsKey($vnicPerf.ID)) {$vnicRecvPerfMap[$vnicPerf.ID]; } else { 0;}
$recvKBytesValue = if ($recvKBytes[0] -ne $null) {$recvKBytes[0];} else {0;}
$sentKBytesValue = if ($vnicPerf.PerformanceHistory[0] -ne $null) {$vnicPerf.PerformanceHistory[0];} else {0;}
$pBag.AddValue('CounterValueReceived', [double]$recvKBytesValue);
$pBag.AddValue('CounterValueSent', [double]$sentKBytesValue);

$pBag
}
}
}
}

function Cleanup
{
param($vmm)

if ($vmm -ne $null)
{
$vmm.Disconnect();
$vmm = $null;
}

$module = get-module -name "virtualmachinemanagercore"

if ($module -ne $null)
{
remove-module -moduleInfo $module;
$module = $null;
}


}

$vmm = $null;
Try
{
#GetAllVNicUsage.ps1 : Gets VNic throughput data from VMM

#error codes
$CredentialNullCode = 25934;
$GetVMMFailureCode = 25935;
$GetVNICFailureCode = 25936;



$oAPI = New-Object -comObject 'MOM.ScriptAPI'

$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.Report.VNicUsageCollection";
$errevent = [System.Diagnostics.EventLogEntryType]::Error;


$error.Clear();

$cred = $null;
if ($domain -AND $username -AND $pass)
{
#Append domain to get domain\username
$domainUser = $domain + "\" + $username;

#Create Cred object
$securePass = ConvertTo-SecureString -AsPlainText $pass -force
$cred = New-Object System.Management.Automation.PSCredential $domainUser, $securePass;
}

$error.Clear();
$module = get-module -name "virtualmachinemanagercore"
if ($module -eq $null)
{
$modulePath = get-itemproperty -path "HKLM:\Software\Microsoft\Microsoft System Center Virtual Machine Manager Administrator Console\Setup";
Import-Module ($modulePath.InstallPath + "bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1");
}

if ($cred -eq $null)
{
$evt.WriteEntry("Credentials are null for user: " + $domainUser, $errevent, $CredentialNullCode);
return;
}

$vmm = Get-SCVMMServer $VMMServer -Credential $cred;
if ($vmm -eq $null)
{
$evt.WriteEntry("VMM Server was null" + $error, $errevent, $GetVMMFailureCode);
return;
}
$error.Clear();
$vnicSentPerf = Get-SCPerformanceData -AllVNIC -PerformanceCounter NetworkIOSent -VMMServer $vmm
$vnicRecvPerf = Get-SCPerformanceData -AllVNIC -PerformanceCounter NetworkIOReceived -VMMServer $vmm

if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $errevent, $GetVNICFailureCode);
return;
}
else
{
$vnicRecvPerfMap = @{}
foreach ($perfdata in $vnicRecvPerf)
{
$vnicRecvPerfMap.Add($perfdata.ID, $perfdata.PerformanceHistory)
}

ProducePerfPropertyBags -vnicSentPerf $vnicSentPerf -vnicRecvPerfMap $vnicRecvPerfMap
}
}
Finally
{
Cleanup -vmm $vmm
}
</Script></ScriptBody>
<Parameters>$Config/Parameters$</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<ObjectName>Virtual Nic</ObjectName>
<CounterName>$Data/Property[@Name='CounterName']$</CounterName>
<InstanceName>$Data/Property[@Name='InstanceName']$</InstanceName>
<Value>$Data/Property[@Name='CounterValue']$</Value>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS1"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>SystemPerf!System.Performance.Data</OutputType>
</DataSourceModuleType>