I want to monitor other data of my Exchange database than the default sensors of PRTG provide. Is it possible to show database size, whitespace size, and search index size per mailbox database in PRTG?
How can I monitor additional values of Exchange databases?
Votes:
0
8 Replies
Votes:
0
This article applies as of PRTG 22
Monitoring more Exchange database values using a PowerShell script
The Exchange Database (PowerShell) sensor can monitor the size of a database and can show if it is valid and mounted. If you need more or other data of your Exchange database, you can set up your individual PowerShell script and monitor it with an EXE/Script Advanced sensor.
This is also what one of our customers did who needed the following data per mailbox database:
- Size of database
- Size of whitespace (free space within the database that is used before the edb itself grows)
- Size of search index
We are happy that this customer shared the respective PowerShell script (see below) with us. Thank you!
How to use the PowerShell script
- Open a text editor.
- Copy the source code from below and paste it into the editor.
- Adjust the connection URI at the beginning of the script so that it fits your Exchange server.
- Save the file with the extension .ps1, for example, ExchangeDBstat.ps1.
- Copy this file to your PRTG program directory, subfolder \Custom Sensors\EXEXML, on the probe system that monitors your Exchange server.
- In PRTG, add an EXE/Script Advanced sensor to the Exchange database device.
- Select the file you created (here: ExchangeDBstat.ps1) from the list of scripts.
- In the section Security Context, select the option Use Windows credentials of parent device.
- You can leave the other settings unchanged.
- Click Create to add the sensor. The sensor will start to show you mailbox database size, whitespace size, and search index size after a few moments.
Note: We do not offer support for custom sensors provided by customers. Of course, you are free to adjust the script according to your needs.
Script
#-----Please adjust to your Exchange server: $CURI="http://exchangeserver.domain.tld/PowerShell/" #-------------- Function SizeInBytes ($itemSizeString) { $posOpenParen = $itemSizeString.IndexOf("(") + 1 $numCharsInSize = $itemSizeString.IndexOf(" bytes") - $posOpenParen $SizeInBytes = $itemSizeString.SubString($posOpenParen,$numCharsInSize).Replace(",","") return $SizeInBytes } $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $CURI -Authentication Kerberos Import-PSSession $Session -DisableNameChecking $dbs = Get-MailboxDatabase -Status $result= "<?xml version=`"1.0`" encoding=`"Windows-1252`" ?>`r`n" $result+="<prtg>`r`n" foreach($db in $dbs) { $dbname=$db.name $dbsize=SizeInBytes($db.DatabaseSize) $whitespace=SizeInBytes($db.availablenewmailboxspace) $edbFilePath = ("\\"+$db.ServerName+"\"+ $db.EdbFilePath.tostring().replace(":","$")) $i = $edbFilePath.LastIndexOf('\') $edbFilePath = $edbFilePath.Remove($i+1) $guid = $db.Guid.ToString() $dir = (get-childitem $edbFilePath | where { $_.Name.Contains($guid) }) $idxdir=$edbFilePath+$dir $idxsize=(Get-ChildItem $idxdir | Measure-Object -Property Length -Sum).Sum $result+=" <result>`r`n" $result+=" <channel>DB-Size "+$dbname+"</channel>`r`n" $result+=" <unit>BytesFile</unit>`r`n" $result+=" <value>"+$dbsize+"</value>`r`n" $result+=" </result>`r`n" $result+=" <result>`r`n" $result+=" <channel>Whitespace "+$dbname+"</channel>`r`n" $result+=" <unit>BytesFile</unit>`r`n" $result+=" <value>"+$whitespace+"</value>`r`n" $result+=" </result>`r`n" $result+=" <result>`r`n" $result+=" <channel>Size Index "+$dbname+"</channel>`r`n" $result+=" <unit>BytesFile</unit>`r`n" $result+=" <value>"+$idxsize+"</value>`r`n" $result+=" </result>`r`n" } $result+=" <text>OK</text>`r`n" $result+="</prtg>`r`n" $result remove-pssession -session $Session Exit 0
More
Created on Feb 11, 2015 5:27:16 PM by
Gerald Schoch [Paessler Support]
Last change on Dec 29, 2022 10:12:06 AM by
Brandy Greger [Paessler Support]
Votes:
1
For anyone who wants to monitor the Content Index State I use this script. Remember to set each channel to use Value Lookup from prtg.standardlookups.exchangedag.contentindexstate so it shows the correct text values.
#-----Please adjust to your Exchange server: $CURI = "http://exchangeserver.domain.tld/PowerShell/" #-------------- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $CURI -Authentication Kerberos Import-PSSession $Session -DisableNameChecking $dbs = Get-MailboxDatabase -Status $result= "<?xml version=`"1.0`" encoding=`"Windows-1252`" ?>`r`n" $result+="<prtg>`r`n" foreach($db in $dbs) { $dbname=$db.name $idxstate=Get-MailboxDatabaseCopyStatus -Identity $dbname | Select -ExpandProperty ContentIndexState $idxstatevalue = switch ($idxstate) { "Healthy" {0} "Crawling" {1} default {2} } $result+=" <result>`r`n" $result+=" <channel>Index State "+$dbname+"</channel>`r`n" $result+=" <value>"+$idxstatevalue+"</value>`r`n" $result+=" </result>`r`n" } $result+="</prtg>`r`n" $result remove-pssession -session $Session exit 0
Votes:
0
Dear Jeroen thank you for the script, this is actually part of the Exchange DAG-Sensor(channel 8).
Votes:
0
Correct, but sadly the sensor doesn't work for a single non-DAG Exchange server. So I had to make one. Unless I looked wrong :)
Votes:
0
Jeroen, you are of course correct, and so the script will definitely have its use. Thank you for it!
Votes:
0
Thanks for this script. Does anyone know how I could modify it to show whitespace as a percentage of the total database size?
Votes:
0
Jeroen's script was exactly what I was looking to accomplish. Just to expand on what he said about the value lookup for the Index states, you can specify the lookup in the output from the script rather than needing to configure it on each channel:
$result+=" <result>`r`n" $result+=" <channel>Index State "+$dbname+"</channel>`r`n" $result+=" <value>"+$idxstatevalue+"</value>`r`n" $result+=" <valuelookup>prtg.standardlookups.exchangedag.contentindexstate</valuelookup>`r`n" $result+=" </result>`r`n"
Votes:
0
Hi Kyle,
Great addition, thank you. :)
Best regards.
Add comment