Exc15.Custom.Probe.DBPerfCollection (ProbeActionModuleType)
Element properties:
Member Modules:
Source Code:
<ProbeActionModuleType ID="Exc15.Custom.Probe.DBPerfCollection" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ServerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Debug" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>DBPerfCollectorDS.ps1</ScriptName>
<ScriptBody><Script>
param($serverName,$Debug)
$api = New-Object -comObject 'MOM.ScriptAPI'
$api.LogScriptEvent('Customdbperfcoll.ps1',1409,4,'connecting to ' + $servername)
Function Load-ExchangeSnapin
{
if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) )
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
}
Load-ExchangeSnapin
Function LogDebugInfo ($rule,$eventtext)
{
$api.LogScriptEvent($rule,1410,4,$eventtext)
}
# Get the ExchangeServer object.
$exchangeServer = Get-ExchangeServer -Identity $serverName;
if ($exchangeServer -eq $null)
{
$message='Cannot find exchnage server'
$api.LogScriptEvent($EVENT_SOURCE,1403, 2, $message);
}
$count=0
$DBs=Get-MailboxDatabase -Server $serverName -Status
#|where {$_.Mounted -match 'true'}
foreach($DB in $DBs)
{
# we will create one property bag for each performance counter we want to collect
#collect dasys since last full and incremental backup
$lastfull = $DB.lastfullbackup
if (!$lastfull)
{
$fullago = 99
}
else
{
$fullago = $now - $lastfull
$fullago = $fullago.Days
}
$lastinc = $DB.lastincrementalbackup
if (!$lastinc)
{
$incago = 99
}
else
{
$incago = $now - $lastinc
$incago = $incago.Days
}
If($debug)
{
$message=' MBX DB= '+$DB.identity.Name+' count : ' + $mbxcount
LogDebugInfo 'ExchDatabaseBackup' $message
}
$bag = $api.CreatePropertyBag()
$bag.AddValue('DatabaseName',$DB.identity.Name)
$bag.AddValue('LastFullAge',$fullago)
$bag.AddValue('BackupType','Full')
$bag.AddValue('Counter','Backupage')
$bag
$bag = $api.CreatePropertyBag()
$bag.AddValue('DatabaseName',$DB.identity.Name)
$bag.AddValue('LastFullAge',$incago)
$bag.AddValue('BackupType','Incremental')
$bag.AddValue('Counter','Backupage')
$bag
#collect Exchange database size
[int]$size= $DB.DatabaseSize.toMB()
If($debug)
{
$message=' MBX DB= '+$DB.identity.Name+' Size : ' + $size
LogDebugInfo 'ExchDatabaseSize' $message
}
$bag = $api.CreatePropertyBag()
$bag.AddValue('DatabaseName',$DB.identity.Name)
$bag.AddValue('Size',$size)
$bag.AddValue('Counter','DBSize')
$bag
#collect Exchange database whitespace
[int]$availablespace= $DB.AvailableNewMailboxSpace.toMB()
If($debug)
{
$message=' MBX DB= '+$DB.identity.Name+' Whitespace: ' + $availablespace
LogDebugInfo 'ExchDatabaseWhitespace' $message
}
$bag = $api.CreatePropertyBag()
$bag.AddValue('DatabaseName',$DB.identity.Name)
$bag.AddValue('Whitespace',$availablespace)
$bag.AddValue('Counter','DBWhitespace')
$bag
#collect Exchange database Mailbox Count
$mbxcount=0
$mbxcount=($DB|get-mailbox -ResultSet Unlimited).count
If($debug)
{
$message=' MBX DB= '+$DB.identity.Name+' MbxCount: ' + $mbxcount
LogDebugInfo 'ExchDatabaseMailboxCount' $message
}
$bag = $api.CreatePropertyBag()
$bag.AddValue('DatabaseName',$DB.identity.Name)
$bag.AddValue('MBXCount',$mbxcount)
$bag.AddValue('Counter','MailboxCount')
$bag
#collect Exchange database Login latency
$latency=0
If ($DB.Mounted)
{
[int]$latency= (Test-MAPIConnectivity -Database $DB.identity.Name).Latency.Milliseconds
If($debug)
{
$message=' MBX DB= '+$DB.identity.Name+' MbxCount: ' +$latency
LogDebugInfo 'ExchDatabaseMailboxLoginLatency' $message
}
$bag = $api.CreatePropertyBag()
$bag.AddValue('DatabaseName',$DB.identity.Name)
$bag.AddValue('Latency',$latency)
$bag.AddValue('Counter','DBLoginLatency')
$bag
}
}
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>serverName</Name>
<Value>$Config/ServerName$</Value>
</Parameter>
<Parameter>
<Name>Debug</Name>
<Value>$Config/Debug$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>360</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>