Microsoft.SystemCenter.VirtualMachineManager.2016.CloudFabricUsageUnitMonitorType (UnitMonitorType)

Element properties:

RunAsDefault
AccessibilityPublic
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Scheduler Default
Probe ProbeAction Microsoft.SystemCenter.VirtualMachineManager.2016.PowerShellProbeActionModuleType Default
CDOnCritical ConditionDetection System.ExpressionFilter Default
CDOnHealthy ConditionDetection System.ExpressionFilter Default
CDOnWarning ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$
WarningThresholddouble$Config/WarningThreshold$
CriticalThresholddouble$Config/CriticalThreshold$

Source Code:

<UnitMonitorType ID="Microsoft.SystemCenter.VirtualMachineManager.2016.CloudFabricUsageUnitMonitorType" Accessibility="Public">
<MonitorTypeStates>
<MonitorTypeState ID="CloudFabricHealthy" NoDetection="false"/>
<MonitorTypeState ID="CloudFabricWarning" NoDetection="false"/>
<MonitorTypeState ID="CloudFabricCritical" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<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="WarningThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CriticalThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CloudId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VMMServer" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="WarningThreshold" Selector="$Config/WarningThreshold$" ParameterType="double"/>
<OverrideableParameter ID="CriticalThreshold" Selector="$Config/CriticalThreshold$" ParameterType="double"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="Probe" TypeID="Microsoft.SystemCenter.VirtualMachineManager.2016.PowerShellProbeActionModuleType">
<Parameters>
<Parameter>
<Name>VMMServer</Name>
<Value>$Config/VMMServer$</Value>
</Parameter>
<Parameter>
<Name>domain</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Domain$</Value>
</Parameter>
<Parameter>
<Name>username</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>pass</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Password$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>param($VMMServer, $domain, $username, $pass)
$MBFactor = 1024 * 1024;
$GBFactor = $MBFactor * 1024;
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;

}

function GetPercent
{
param($numerator, $denominator)
$percent = 0;
if ($denominator -ne 0)
{
$percent = [Math]::Round(($numerator * 100) / $denominator);
}

$percent;
}

function GetHostMemory
{
param ($hostObj)
$memory = 0;

if ($hostObj -ne $null)
{
$memory = $hostObj.TotalMemory / $MBFactor ;
}

$memory
}

function GetHostStorage
{
param ($hostObj)
$storage = 0;

if ($hostObj -ne $null)
{
$storage = $hostObj.TotalStorageCapacity / $GBFactor ;
}

$storage
}

function GetHostGroupsCapacity
{
param($hostGroups, $VMMServer)

$memoryCapacityMBSum = 0;
$storageCapacityGBSum = 0;
if ($hostGroups -ne $null -and $hostGroups.Count -ne $null)
{
foreach ($hostGroup in $hostGroups)
{
if ($hostGroup -ne $null)
{
# workaround for AllChildHosts property not being populated
# need to call Get-VMHost once per server connection
$tempHost = Get-SCVMHost -VMMServer $VMMServer
if ($hostGroup.AllChildHosts -eq $null -or $hostGroup.AllChildHosts.Count -eq 0)
{
$evt.WriteEntry("AllChildHosts property is null. Can't compute capacity, so monitor wouldn't work", $errevent, $GetVMMFailureCode);
}

if ($hostGroup.AllChildHosts -ne $null)
{
#AllChildHosts property contains a flatened list of all hosts under a host group
foreach ($h in $hostGroup.AllChildHosts)
{
$memoryCapacityMBSum += GetHostMemory $h;
$storageCapacityGBSum += GetHostStorage $h;
}
}
}
}
}
$memoryCapacityMBSum;
$storageCapacityGBSum;
}


function GetVMWareResourcePoolCapacity
{
param($resourcePool)
$memoryCapacityMBSum = 0;
$storageCapacityGBSum = 0; # there are no storage limits in VMWare resource pool
if ($resourcePool.IsMemoryReservationUnlimited -ne $true)
{
$memoryCapacityMBSum += $resourcePool.MemoryReservationLimitBytes / $MBFactor;
}

$memoryCapacityMBSum;
$storageCapacityGBSum;
}

function GetCloudFabricCapacity
{
param($cloud, $VMMServer)
if ($cloud -ne $null)
{
if ($cloud.HostGroup -ne $null)
{
$fabcapacityHostGroups = GetHostGroupsCapacity -hostGroups $cloud.HostGroup -VMMServer $VMMServer
$fabcapacityHostGroups
}
elseif ($cloud.VMWareResourcePool -ne $null)
{
$fabcapacityResourcePool = GetVMWareResourcePoolCapacity -resourcePool $cloud.VMWareResourcePool
$fabcapacityResourcePool
}
}
}

function UpdateCloudPropertyBag
{
param($cloud, $usage, $capacity, $propertyBag)

if ($cloud -ne $null -and $usage -ne $null -and $capacity -ne $null)
{
$memoryUsageCapacityPercent = GetPercent $usage.MemoryUsageMB $capacity[0];
$storageCurrentCapacityPercent = GetPercent $usage.StorageCurrentGB $capacity[1];

$propertyBag.AddValue($cloud.Id.ToString() + "-Memory", $memoryUsageCapacityPercent);
$propertyBag.AddValue($cloud.Id.ToString() + "-Storage", $storageCurrentCapacityPercent);

}
}

$vmm = $null;
Try
{
# FabricCloudCapacity.ps1 - calculates the ratio of cloud usage to its fabric capacity for all clouds in VMM

#error codes
$CredentialNullCode = 25934;
$GetVMMFailureCode = 25935;
$GetCloudFailureCode = 25936;
$ScriptSuccessCode = 25940;

$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.2016.Monitor.FabricCloudMonitor";

$errevent = [System.Diagnostics.EventLogEntryType]::Error;
$infoevent = [System.Diagnostics.EventLogEntryType]::Information;

$oAPI = New-Object -comObject 'MOM.ScriptAPI'
$pBag = $oAPI.CreatePropertyBag()


$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;

}

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

$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");
}

$error.Clear();
$vmm = Get-SCVMMServer $VMMServer -Credential $cred;
if ($error.Count -ne 0)
{
$evt.WriteEntry("Get VMM Server failed:" + $error[0].Exception.StackTrace, $errevent, $GetVMMFailureCode);
return;
}

$AllClouds = Get-SCCloud -VMMServer $vmm;

if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $errevent, $GetCloudFailureCode);
return;
}
else
{
$error.Clear()
if ($AllClouds -ne $null)
{
if ( $AllClouds.Count -ne $null)
{
foreach ($cloud in $AllClouds)
{
$usage = Get-SCCloudUsage -Cloud $cloud -VMMServer $vmm
$fabCapacity = GetCloudFabricCapacity -cloud $cloud -VMMServer $vmm

UpdateCloudPropertyBag -cloud $cloud -usage $usage -capacity $fabCapacity -propertyBag $pBag
}
$pBag
}
else
{
$usage = Get-SCCloudUsage -Cloud $cloud -VMMServer $vmm
$fabCapacity = GetCloudFabricCapacity -cloud $AllClouds -VMMServer $vmm

UpdateCloudPropertyBag -cloud $AllClouds -usage $usage -capacity $fabCapacity -propertyBag $pBag
$pBag
}
}
}
}
Finally
{
Cleanup -vmm $vmm
}</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="CDOnHealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/CloudId$']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">$Config/WarningThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOnWarning" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/CloudId$']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/WarningThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/CloudId$']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">$Config/CriticalThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOnCritical" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/CloudId$']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/CriticalThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="CloudFabricHealthy">
<Node ID="CDOnHealthy">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="CloudFabricWarning">
<Node ID="CDOnWarning">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="CloudFabricCritical">
<Node ID="CDOnCritical">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>