New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


How can I monitor additional values of Exchange databases?

Votes:

0

Your Vote:

Up

Down

I want to monitor other data of my Exchange database than the default sensors of PRTG provides. 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 Mar 19, 2015 3:44:13 PM by  Martina Wittmann [Paessler Support]



8 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 14 or later

Monitoring More Exchange Database Values Using a PowerShell Script

The Exchange Database (Powershell) Sensor which comes out of the box with PRTG can monitor the size of a database and shows 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 needs the following data per mailbox database:

  • Size of database
  • Size of white space (free space within the database which is used before the edb itself grows)
  • Size of search index

We are happy that this customer shares the according 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 to your Exchange server.
  4. Save the file with the extension .ps1, for example, “ExchangeDBstat.ps1”
  5. Copy this file into your PRTG installation folder, subfolder \Custom Sensors\EXEXML, on the system running the probe that monitors your Exchange server.
  6. In PRTG, add an EXE/Script Advanced Sensor to the Exchange database device.
    1. Choose ExchangeDBstat.ps1 from the list of scripts.
    2. In section Security Context, choose the option Use Windows credentials of parent device
    3. You can leave the other settings unchanged.
    4. Click Continue to add the sensor. The sensor will start to show you mailbox database size, white space size, and search index size in 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

See Also

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

Last change on Mar 17, 2015 12:08:44 PM by  Gerald Schoch [Paessler Support]



Votes:

1

Your Vote:

Up

Down

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 by  Jeroen Huurman (60) 2 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Jeroen Huurman (60) 2 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Rodger (0)



Votes:

0

Your Vote:

Up

Down

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 by  Kyle Mountney (0)



Votes:

0

Your Vote:

Up

Down

Hi Kyle,

Great addition, thank you. :)

Best regards.

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



Please log in or register to enter your reply.


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.