Are there any tips & tricks?
This article applies to PRTG Network Monitor 16 or later
How to create a WMI Custom or WMI Custom String Sensor
Windows Management Instrumentation (WMI) is a powerful way to monitor a plethora of things on your Windows computer. PRTG already comes with the most useful WMI counter sensors, but there are lots of other counters you might be interested in—especially when you have written your own WMI extensions.
Step 1: Find the counter you want to monitor
To monitor a specific counter you have to determine its namespace, its class, and its name.
- Microsoft have documented all their WMI counters in their Windows documentation on MSDN. Browse through the classes to determine the necessary information.
- Use Google (or your favorite search engine) for finding counters, include keywords like WMI, counter, or class.
- If you have written your own extension, you already know the necessary information, of course.
Step 2: Create the WMI query
If you know the class and the name of a specific counter, you put them in an expression of the WMI Query Language (WQL) with this syntax:
SELECT countername FROM counterclass
Replace countername and counterclass with your individual data.
A complete reference for WQL is here: WQL (SQL for WMI) on MSDN
Note: For correct monitoring, PRTG needs a single number value or string (depending on the sensor type you use) in a single row. If your query returns more than one result, you need to narrow down the result set using a WHERE clause in this syntax:
SELECT countername FROM counterclass WHERE anothercounter = value
This is documented in the Microsoft article WHERE Clause.
If you want to use the LIKE operator for more flexibility, see also the article LIKE Operator.
Step 3: Test your WMI query in WMI Tester
Test your WQL query with our WMI Tester.
- Fill in the credentials for the target computer and click the Test! button to make sure WMI is basically up and running.
- Open the Advanced tab, select Query/Custom, and enter your query. Also enter the correct namespace (for Windows standard WMI classes it is root\CIMV2). Click Test!
- If you encounter errors, check the syntax of your query and the namespace.
Read more about the usage of WMI Tester in its section of the WMI Tools Overview
Step 4: Implement and use the sensor in PRTG
To use your query in PRTG, you have to save it to a file that
- contains only the (one) query
- has a .wql extension to its filename
- is placed in the \Custom Sensors\WMI WQL scripts subfolder of your PRTG probe installation.
Make sure you add the correct custom WMI sensor type for the returned value:
- For integer and float values, add the WMI Custom sensor.
- For strings, add the WMI Custom String sensor. This sensor type will show the returned value in the sensor message and will not add a channel for it.
System Uptime of the target computer:
SELECT SystemUpTime FROM Win32_PerfFormattedData_PerfOS_System
Average Disk Bytes Per Read on Drive D:
SELECT AVGDiskBytesPerRead FROM Win32_PerfRawData_PerfDisk_LogicalDisk WHERE Name = 'D:'
- The WMI Custom sensor supports only single number values (integers and floats) as result from WQL queries. If your query returns one or more of the following, the sensor will not be able to process the result:
- string values, such as names: use the WMI Custom String sensor
- more than one column (two or more values horizontally in the result table of WMI Tester): you must specify only one counter in the query.
- more than one row (two or more values vertically in the result table of WMI Tester): you have to narrow down the result list with a WHERE clause.
- It is important that you copy the WQL file with your query to the computer where the PRTG probe that monitors the target computer is installed. If the file is placed on the target computer (or in case of a remote probe on the PRTG server), PRTG will not show the file in the selection list of the Add Sensor dialog.
- Always ensure you use the correct namespace in both the WMI Tester and in the PRTG settings of the sensor.
- Find more information on the WMI Query Language (WQL) in the Microsoft Developer Network.
- You can also monitor any Windows Performance Counters with PRTG: PerfCounter Custom Sensor
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.