Tipo de monitor de unidad de uso de nubes de System Center 2019+ Virtual Machine Manager
Microsoft.SystemCenter.VirtualMachineManager.CloudUsageUnitMonitorType (UnitMonitorType)
Este tipo de monitor se usa para comprobar el uso de nubes privadas
Element properties:
Member Modules:
Overrideable Parameters:
Source Code:
<UnitMonitorType ID="Microsoft.SystemCenter.VirtualMachineManager.CloudUsageUnitMonitorType" Accessibility="Public">
<MonitorTypeStates>
<MonitorTypeState ID="CloudUsageHealthy" NoDetection="false"/>
<MonitorTypeState ID="CloudUsageCritical" 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="CriticalThreshold" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PropertyValue" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VMMId" 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="CriticalThreshold" Selector="$Config/CriticalThreshold$" ParameterType="int"/>
</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.PowerShellProbeActionModuleType">
<Parameters>
<Parameter>
<Name>VMMServer</Name>
<Value>$Config/VMMServer$</Value>
</Parameter>
<Parameter>
<Name>CriticalThreshold</Name>
<Value>$Config/CriticalThreshold$</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, $CriticalThreshold, $domain, $username, $pass)
function Cleanup
{
$module = get-module -name "virtualmachinemanagercore"
if ($module -ne $null)
{
remove-module -moduleInfo $module
}
}
function UpdateCloudPropertyBag
{
param($cloudId, $cloudCap, $cloudUsage, $pBag, $CriticalThreshold)
$cpuUsagePercent= 0;
$quotePercent = 0;
$memPercent = 0;
$stoagePercent = 0;
$VMUsagePercent = 0;
if ($cloudCap -ne $null)
{
if ($cloudCap.UseCPUCountMaximum -ne $true)
{
$cpuUsagePercent = $cloudUsage.CPUUsageCount/$cloudcap.CPUCount * 100;
}
if ($cloudCap.UseMemoryMBMaximum -ne $true)
{
$memPercent = $cloudUsage.MemoryUsageMB/$cloudcap.MemoryMB * 100;
}
if ($cloudCap.UseStorageGBMaximum -ne $true)
{
$stoagePercent = $cloudUsage.StorageCurrentGB/$cloudcap.StorageGB * 100;
}
if ($cloudCap.UseCustomQuotaCountMaximum -ne $true)
{
$quotePercent = $cloudUsage.CustomQuotaUsageCount/$cloudcap.CustomQuotaCount * 100;
}
if ($cloudCap.UseVMCountMaximum -ne $true)
{
$VMUsagePercent = $cloudUsage.VMUsageCount/$cloudcap.VMCount * 100;
}
$pBag.AddValue($cloudId.ToString() + "-CPUUsage", $cpuUsagePercent)
$pBag.AddValue($cloudId.ToString() + "-CustomQuotaUsage", $quotePercent)
$pBag.AddValue($cloudId.ToString() + "-MemoryUsageMB", $memPercent)
$pBag.AddValue($cloudId.ToString() + "-StorageUsageGB", $stoagePercent)
$pBag.AddValue($cloudId.ToString() + "-VMUsage", $VMUsagePercent)
$pBag.AddValue($cloudId.ToString() + "-CriticalThreshold", $CriticalThreshold)
}
}
$vmm = $null
Try
{
#error codes
$CredentialNullCode = 25934;
$GetVMMFailureCode = 25935;
$oAPI = New-Object -comObject 'MOM.ScriptAPI'
$pBag = $oAPI.CreatePropertyBag()
$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.Monitor.CloudCPUUsageCount";
$infoevent = [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;
}
if ($cred -ne $null)
{
$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, $infoevent, $GetVMMFailureCode);
return;
}
else
{
$AllClouds = Get-SCCloud -VMMServer $vmm ;
if ($AllClouds -ne $null)
{
if ( $AllClouds.Count -ne $null)
{
foreach ($cloud in $AllClouds)
{
$cloudUsage = Get-SCCloudUsage -Cloud $cloud -VMMServer $vmm;
$cloudCap = Get-SCCloudCapacity -Cloud $cloud -VMMServer $vmm;
UpdateCloudPropertyBag -cloudId $cloud.Id -cloudCap $cloudCap -cloudUsage $cloudUsage -pBag $pBag -CriticalThreshold $CriticalThreshold
}
}
else
{
$cloudUsage = Get-SCCloudUsage -Cloud $AllClouds -VMMServer $vmm;
$cloudCap = Get-SCCloudCapacity -Cloud $AllClouds -VMMServer $vmm;
UpdateCloudPropertyBag -cloudId $AllClouds.Id -cloudCap $cloudCap -cloudUsage $cloudUsage -pBag $pBag -CriticalThreshold $CriticalThreshold
}
}
}
}
else
{
$evt.WriteEntry("Credentials are null for user: " + $domainUser, $errevent, $CredentialNullCode);
return;
}
$pBag
}
Finally
{
if ($vmm -ne $null)
{
$vmm.Disconnect();
}
Cleanup
}</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="CDOnhealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/VMMId$']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">$Config/CriticalThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOnCritical" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/VMMId$']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/CriticalThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="CloudUsageHealthy">
<Node ID="CDOnhealthy">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="CloudUsageCritical">
<Node ID="CDOnCritical">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>