Hyper-V MPE 2016 Dynamic Memory Maximum Load Per Host

HyperV.MPE.2016.DynamicMemoryMaximumLoadPerHost.Monitor (UnitMonitor)

Knowledge Base article:

Summary

This monitor calculates the relationship between sum of all maximum virtual machine memory in a host and the physical memory of the host.

Formula

((SUM of Maximum RAM Memory for all running VMs with DM + SUM of RAM Memory of all running VMs with Static Memory) / (Physical Memory))*100

Element properties:

TargetMicrosoft.Windows.HyperV.2016.ServerRole
Parent MonitorSystem.Health.AvailabilityState
CategoryCustom
EnabledFalse
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeHyperV.MPE.2016.Powershell.PS.Script.MonitorType.TwoStates
RemotableTrue
AccessibilityInternal
Alert Message
Hyper-V MPE 2016 Alert: Dynamic Memory Maximum Load Per Host
Sum of memory for all VMs in this host is over the Physical Memory of the host.
RunAsDefault

Source Code:

<UnitMonitor ID="HyperV.MPE.2016.DynamicMemoryMaximumLoadPerHost.Monitor" Accessibility="Internal" Enabled="false" Target="MSWinHV2016Dis!Microsoft.Windows.HyperV.2016.ServerRole" ParentMonitorID="SHLib!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="HVMPELib!HyperV.MPE.2016.Powershell.PS.Script.MonitorType.TwoStates" ConfirmDelivery="true">
<Category>Custom</Category>
<AlertSettings AlertMessage="HyperV.MPE.2016.DynamicMemoryMaximumLoadPerHost.Monitor_AlertMessageResourceID">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
</AlertSettings>
<OperationalStates>
<OperationalState ID="ConditionSuccess" MonitorTypeStateID="Healthy" HealthState="Success"/>
<OperationalState ID="ConditionError" MonitorTypeStateID="Critical" HealthState="Error"/>
</OperationalStates>
<Configuration>
<SyncTime/>
<IntervalSeconds>300</IntervalSeconds>
<ScriptName>DynamicMemoryMaximumLoadPerHost.ps1</ScriptName>
<ScriptBody><Script>

param($Threshold)

$api = New-Object -comObject 'MOM.ScriptAPI'
$bag = $api.CreatePropertyBag()

$result = get-vm

$totalMem = Get-WMIObject -class win32_computersystem | select-object totalphysicalmemory

$sum = 0

foreach ($item in [array] $result)
{
if ($item.DynamicMemoryEnabled)
{$sum = $sum + ((($item.MemoryMaximum/1024)/1024)/1024)}
else
{$sum = $sum + ((($item.MemoryStartup/1024)/1024)/1024)}
}


$MemGB = (($totalmem.totalphysicalmemory/1048576)/1024)
$UsedPerc = ($sum/$MemGB)*100
$bag.AddValue('UsedPerc', [int]$UsedPerc)
$bag
</Script></ScriptBody>
<TimeoutSeconds>60</TimeoutSeconds>
<HealthyExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='UsedPerc']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">99</Value>
</ValueExpression>
</SimpleExpression>
</HealthyExpression>
<CriticalExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='UsedPerc']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">99</Value>
</ValueExpression>
</SimpleExpression>
</CriticalExpression>
<Parameters>
<Parameter>
<Name>Threshold</Name>
<Value>90</Value>
</Parameter>
</Parameters>
</Configuration>
</UnitMonitor>