Monitoring a (Windows) DHCP server
As I PRTG user I would like to monitor the number of remaining leases and usage of available leases.

Monitoring your Windows DHCP server in PRTG to track remaining leases and usage of available leases is crucial for proactive network management. Here's how you can achieve this, leveraging different PRTG sensor types:
Methods for Monitoring DHCP Lease Usage in PRTG
There are a few primary ways to monitor DHCP lease usage in PRTG on a Windows server:
- SNMP Custom Sensor (Recommended for direct lease count)
- EXE/Script Advanced Sensor with PowerShell (Most flexible and detailed)
- PRTG DHCP Sensor (Basic availability check)
Let's break down each method:
Method 1: SNMP Custom Sensor (for specific OIDs)
Windows DHCP servers expose information about their scopes and lease usage via SNMP. This is often the simplest way to get direct numbers for available/used leases per scope.
Prerequisites:
- SNMP Service enabled on your Windows DHCP Server: Make sure the SNMP service is installed and running on your DHCP server, and configure a community string that PRTG can use.
- PRTG Probe: Your PRTG probe needs network access to the DHCP server over SNMP (UDP port 161).
Steps:
- Identify DHCP OIDs: The key to using an SNMP Custom sensor is knowing the correct Object Identifiers (OIDs) for the data you want. For Windows DHCP, common OIDs relate to:
- Total Addresses in Scope: 1.3.6.1.4.1.311.1.3.2.1.1.2.<DHCP_Scope_Network_ID>
- Addresses Available (Free) in Scope: 1.3.6.1.4.1.311.1.3.2.1.1.3.<DHCP_Scope_Network_ID>
- Addresses Used (In Use) in Scope: 1.3.6.1.4.1.311.1.3.2.1.1.4.<DHCP_Scope_Network_ID>
- Important: Replace <DHCP_Scope_Network_ID> with the actual network ID of your DHCP scope. For example, if your scope is 192.168.1.0, the OID for available addresses would be 1.3.6.1.4.1.311.1.3.2.1.1.3.192.168.1.0.
- Tip: You can use an SNMP walk tool (like snmpwalk.exe) from a machine with network access to the DHCP server to discover available OIDs and their values for your specific server and scopes.
- Add a Device in PRTG: If you haven't already, add your Windows DHCP server as a device in PRTG.
- Add an SNMP Custom Sensor:
- Right-click on your DHCP server device in PRTG and select Add Sensor.
- Search for "SNMP Custom" and select it.
- Sensor Name: Give it a descriptive name, e.g., "DHCP Scope 192.168.1.0 - Available Leases".
- OID: Enter the specific OID you identified (e.g., 1.3.6.1.4.1.311.1.3.2.1.1.3.192.168.1.0).
- SNMP Credentials: Ensure you're using the correct SNMP community string configured on your DHCP server.
- Data Type: Set the data type (e.g., "Integer" or "Float").
- Unit: You can set the unit to "Leases" or "IPs".
- Repeat this process for each scope and for "Used Leases" if you want separate sensors for those.
- Calculate Usage Percentage (Optional, via Custom Sensor Calculation):
- To get the usage percentage, you'll likely need two SNMP Custom sensors (one for "Addresses Available" and one for "Total Addresses").
- Then, you can create a Custom Sensor (Calculated) in PRTG that uses the values from these two sensors to calculate the percentage: (Total Addresses - Available Addresses) / Total Addresses * 100.
Method 2: EXE/Script Advanced Sensor with PowerShell
This method offers the most flexibility as you can write a PowerShell script to gather highly specific DHCP information, including lease usage, and then output it in a format PRTG can understand.
Prerequisites:
- PowerShell Remoting (or local execution on probe): The PRTG probe needs to be able to execute PowerShell scripts on the DHCP server. This often means enabling PowerShell Remoting on the DHCP server and configuring appropriate permissions for the PRTG agent or user context. Alternatively, if the PRTG probe is running on the DHCP server itself, the script can be executed locally.
- DHCP Server Tools (PowerShell Module): Ensure the "DHCP Server Tools" feature (which includes the DHCP PowerShell module) is installed on the machine where the script will run (either the PRTG probe or the DHCP server itself). You can add this feature with Add-WindowsFeature RSAT-DHCP.
Steps:
- Create a PowerShell Script:
- Here's an example PowerShell script to get DHCP scope utilization. You'll need to save this script (e.g., Get-DhcpScopeUsage.ps1) in the Custom Sensors folder on your PRTG probe.
- PowerShell
- Refinement for AddressesInUse: The way Leases.Count is accessed might vary slightly depending on your Windows Server version. A more robust way to get used addresses might involve Get-DhcpServerv4Lease -ScopeId $scope.ScopeId -ComputerName $DHCPServer | Measure-Object | Select-Object -ExpandProperty Count.
- Dynamic Server Name: The $DHCPServer parameter allows you to specify the DHCP server name. If the sensor is on the DHCP server itself, $env:COMPUTERNAME will work. If the sensor is on a separate probe, you can pass %host in PRTG as a parameter to use the device's IP/DNS name.
- Output Format: The Write-Host lines generate the PRTG-specific output. Each ChannelName:Value pair creates a new channel in the PRTG sensor. \r\n ensures a new line for each channel.
- Add an EXE/Script Advanced Sensor in PRTG:
- Right-click on your DHCP server device in PRTG and select Add Sensor.
- Search for "EXE/Script Advanced" and select it.
- Sensor Name: "DHCP Lease Usage (PowerShell)".
- Program File: Select your PowerShell executable (e.g., C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe).
- Parameters:To execute your script: -ExecutionPolicy Bypass -File "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\Get-DhcpScopeUsage.ps1" -DHCPServer %host
- Adjust the path to your script if you saved it elsewhere.
- %host will automatically pass the IP address or DNS name of the parent device (your DHCP server) to the script.
- Security Context: Choose "Use Windows credentials of parent device" and ensure the account configured for the device has permissions to run DHCP PowerShell cmdlets. You might need to add the user to the "DHCP Users" Active Directory group.
- Configure Channels and Notifications:
- Once the sensor runs successfully, PRTG will automatically detect the channels (e.g., DHCP_Scope_192.168.1.0_Used, DHCP_Scope_192.168.1.0_UsagePercent).
- You can then configure limits and notifications on these channels to alert you when usage reaches a certain threshold (e.g., 80% used).
Method 3: PRTG DHCP Sensor (Basic Availability)
PRTG includes a built-in DHCP sensor. While useful for verifying if a DHCP server is responding and offering IP addresses, it does not directly provide the number of remaining leases or usage percentage for specific scopes. Its primary function is to:
- Send a broadcast message requesting an IP address.
- Report the response time of the DHCP server.
- Show the IP address offered and its lease duration.
- Confirm if any DHCP server is responding.
When to use it:
- To check the basic health and responsiveness of your DHCP service.
- To ensure DHCP is allocating addresses.
How to add:
- Right-click on a probe device (not directly on your DHCP server if it's not the probe itself).
- Select Add Sensor.
- Search for "DHCP Sensor" and select it.
- Configure the sensor by choosing the network card on the probe that will send the broadcast.
Key Considerations for DHCP Monitoring
- SNMP vs. PowerShell:SNMP: Simpler to set up for basic counts if the OIDs are readily available and consistent across your DHCP servers. Less overhead.
- PowerShell: More powerful and flexible. Allows for custom calculations, filtering, and gathering of more granular data. Requires more configuration for remoting/permissions.
- Permissions: Ensure the PRTG probe or the Windows credentials used by the sensor have the necessary permissions to query DHCP server information. For PowerShell, this typically means the user needs to be in the "DHCP Users" group in Active Directory.
- Thresholds and Notifications: Set appropriate warning and error thresholds for your lease usage percentages (e.g., warning at 80% used, error at 90% used). Configure notifications (email, SMS, push) to alert you well before you run out of IP addresses.
- Historical Data and Trending: PRTG will automatically collect historical data, allowing you to visualize trends in DHCP lease usage over time. This is invaluable for capacity planning.
- Multiple Scopes: If you have multiple DHCP scopes on a single server, you'll need to set up individual sensors (either SNMP Custom or tailor your PowerShell script) for each scope to get detailed usage information per scope.
By implementing one or a combination of these methods, you'll gain excellent visibility into your Windows DHCP server's lease utilization and be able to proactively address potential IP address exhaustion issues.