What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How can I monitor additional values of Exchange databases?

Votes:

0

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?

custom-script-exe custom-sensor exchange exchange-database exe-script-sensor exexml mailbox prtg

Created on Feb 11, 2015 5:24:20 PM by  Gerald Schoch [Paessler Support]

Last change on Jul 10, 2019 9:53:13 AM by  Maike Guba [Paessler Support] (2,404) 2 1



8 Replies

Accepted Answer

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

  1. Open a text editor.
  2. Copy the source code from below and paste it into the editor.
  3. Adjust the connection URI at the beginning of the script so that it fits your Exchange server.
  4. Save the file with the extension .ps1, for example, ExchangeDBstat.ps1.
  5. Copy this file to your PRTG program directory, subfolder \Custom Sensors\EXEXML, on the probe system that monitors your Exchange server.
  6. In PRTG, add an EXE/Script Advanced sensor to the Exchange database device.
    1. Select the file you created (here: ExchangeDBstat.ps1) from the list of scripts.
    2. In the section Security Context, select the option Use Windows credentials of parent device.
    3. You can leave the other settings unchanged.
    4. 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

Created on Jun 30, 2016 12:45:45 PM



Votes:

0

Dear Jeroen thank you for the script, this is actually part of the Exchange DAG-Sensor(channel 8).

Created on Jun 30, 2016 2:30:44 PM by  Torsten Lindner [Paessler Support]



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 :)

Created on Jun 30, 2016 2:33:07 PM



Votes:

0

Jeroen, you are of course correct, and so the script will definitely have its use. Thank you for it!

Created on Jul 6, 2016 11:11:54 AM by  Torsten Lindner [Paessler Support]



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?

Created on Mar 22, 2017 11:39:34 AM



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"

Created on Dec 20, 2017 8:03:58 PM



Votes:

0

Hi Kyle,

Great addition, thank you. :)

Best regards.

Created on Dec 20, 2017 8:33:23 PM by  Dariusz Gorka [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.