Are there any tips & tricks?
This article applies to PRTG Network Monitor 19 or later
How to Create a WMI Custom or WMI Custom String Sensor
Windows Management Instrumentation (WMI) is a powerful way to monitor many values 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 has documented all its WMI counters in its Windows documentation on MSDN. Browse through the classes to determine the necessary information.
- Use Google (or your favorite search engine) for finding counters, and 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 can be found on MSDN: WQL (SQL for WMI)
Note: For monitoring correctly, 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 with 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, also see 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 the PRTG program directory.
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.
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.