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 set up custom WMI sensors?
How do I properly configure a WMI custom sensor?
This article applies as of PRTG 22
How to add your own WQL queries using WMI Custom sensors
Use Windows Management Instrumentation (WMI) to monitor counters that are not included in the standard set of WMI sensors in PRTG. To do so, 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 in which your WMI classes are located, beginning with root, for example, root\CIMV2.
- WQL File: Select the WQL script files on the probe system. After sensor 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 system. The path is usually C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\WMI WQL scripts.
Enter a WQL query with one field returning a numeric 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 by using a placeholder system. This allows you to reuse the script for more sensors by 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 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.
Alternatively, if you want the number of entries in the result set to be returned to a direct value from a field, you can use the SELECT COUNT(*) statement.
SELECT COUNT(*) FROM Win32_Process WHERE Name='explorer.exe'
Note: 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 WQL in Microsoft's Developer Network.