I need to monitor WMI counters that are not covered by the built-in WMI sensors set of PRTG. So I have written a few custom WQL scripts to be executed by PRTG. Are there any rules I should follow to setup custom WMI sensors?
This article applies to PRTG Network Monitor 19 or later
How to Add Your Own WQL Queries Using WMI Custom Sensors
If you want to use WMI to monitor counters that are not included in the standard set of WMI sensors in PRTG, you can add your own WMI WQL queries using the WMI Custom sensor or the WMI Custom String sensor.
Relevant Settings for Custom WMI Sensors
- Namespace: Enter the namespace your WMI classes are located in, beginning with root, for example, root\CIMV2.
- WQL File: When creating the sensor, you can select from the WQL script files located on the probe computer. After creation this field is read-only.
- Placeholders: Customize your WQL scripts with up to three placeholders that are replaced with the values you enter in the sensor settings (see below).
Create a .WQL file and store it in the \Custom Sensors\WMI WQL scripts subfolder of the PRTG program directory on the respective probe computer, usually C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\WMI WQL scripts.
Enter a WQL query with one field returning a numerical value for the WMI Custom sensor. If your query returns a string value, use the WMI Custom String sensor. Multiple fields and multiple result rows are not supported.
SELECT Buildnumber FROM Win32_OperatingSystem
You can customize this query using a placeholder system, so you can re-use the script for more sensors, entering different values in the sensor’s settings.
For example, myProcess.wql contains this query:
SELECT <#PH1> FROM Win32_Process WHERE Description='<#PH2>'
Now you can add one sensor that monitors the thread count of the PRTG probe by specifying ThreadCount and PRTG Probe.exe in the <#PH1> and <#PH2> setting fields.
Or you could monitor the working set size of Outlook via <#PH1> = WorkingSetSize and <#PH2> = OUTLOOK.exe
If you want the number of entries in the result set to be returned alternatively to a direct value from a field, you can use the SELECT COUNT(*) statement.
SELECT COUNT(*) FROM Win32_Process WHERE Name='explorer.exe'
Please be aware that using an unrestricted query might result in a timeout error.
- How do I create a WMI Custom Sensor?
- Why do I have to store SQL sensor queries and custom scripts in files on the probe computer?
- Find other articles on WQL in our Knowledge Base.
- Find more information on the WMI Query Language (WQL) in Microsoft's Developer Network.