How to create a WMI Custom 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. This is where the WMI Custom sensor steps in.
Step 1: Find the counter you want to monitor
In order 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 in order 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) in the form
SELECT countername FROM counterclass
(where countername and counterclass are replaced with your data, of course).
A complete reference for WQL is here: WQL (SQL for WMI) on MSDN
Note: For correct monitoring PRTG needs a single number value in a single row. Should your query return more than one result, you need to narrow down the result set using a WHERE clause in the form
SELECT countername FROM counterclass WHERE anothercounter = value
as documented in the Microsoft article WHERE Clause.
If you want to use the LIKE operator for more flexibility, don't overlook this article LIKE Operator.
Step 3: Test your WMI query in WMI Tester
Now you test this his so called query in our WMI Tester:
- Fill in the credentials for the target computer and click on the "Test!" button to make sure that WMI is basically up and running.
- Go to the "Advanced tab", select "Query/Custom" and enter the query. Also enter the correct namespace (for Windows standard WMI classes it's root\CIMV2). Click "Test!"
- Should you encounter errors, check the syntax of your query and/or 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
In order to use your query in PRTG you have to save it to a file which
- contains only the (one) query
- needs a .wql extension to its filename
- is situated in the custom sensors\WMI WQL scripts folder of your PRTG Probe installation.
Examples
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:'
Important: Caveats
- PRTG understands only single number values as result from WQL queries. If your query returns one or more of the following, PRTG won't be able to process the result:
- string values, such as names - the counter isn't usable for PRTG
- 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 you copy the wql file with your query to the computer where the PRTG Probe monitoring the target computer is installed. If the file is copied to the target computer (or in case of a remote probe to the PRTG Server computer) PRTG will not show the file in the selection list of hte "Add sensor" step.
- Always ensure you use the correct namespace either in WMI Tester and in the PRTG settings of the sensor.
Add comment