-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the wmi beats module 42650 #42663
Open
herrBez
wants to merge
24
commits into
elastic:main
Choose a base branch
from
herrBez:improve-the-wmi-beats-module-42650
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f1f09e7
Add the Domain parameter. Remove reference to the IP address
herrBez 64d5706
Merge branch 'main' of github.com:elastic/beats into improve-the-wmi-…
herrBez 30a5f45
Add the domain to the wmi data
herrBez 1186460
Improve the documentation of the WMI module
herrBez 5eff223
Update metricbeat/module/windows/wmi/_meta/docs.asciidoc
herrBez 461c09a
Update metricbeat/module/windows/wmi/_meta/docs.asciidoc
herrBez 1cf6ef4
Add wmi.namespace and rewrite the Configuration section
herrBez 77ab16b
Add section about best-practice and about Arbitrator
herrBez d8f479d
Improve phrasing of the best practices section
herrBez 09a0c2e
Fix the convertDateTime function and add a test for the dates with ti…
herrBez 1fe7f2e
Refactor replace fields with properties to be compliant with WMI docu…
herrBez 4ed5563
Refactor the wmi.include_null and wmi.include_empty_string to a more …
herrBez afbced1
Run make update
herrBez c35c1e7
Make the warning more accurate
herrBez 0974350
Fix typo
herrBez 43af227
Fix linting error
herrBez e05a887
fix the example of the documentation + reorder the parameter definiti…
herrBez 2c23092
Merge branch 'main' into improve-the-wmi-beats-module-42650
herrBez 8249b47
remove reference to fields that should have been removed with the ref…
herrBez ac2f9a9
fix typos and make sure the period is 10 minutes in our examples
herrBez d2ecd8b
Fix the name of the test
herrBez 3ce31bd
Hide the Remote WMI parameters
herrBez a779965
Merge branch 'main' into improve-the-wmi-beats-module-42650
ishleenk17 28ed9a7
Remove remote wmi logic from wmi.go. This can be reactivated by need
herrBez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,143 @@ | ||
The `wmi` metricset of the Windows module reads metrics via Windows Management Instrumentation link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/about-wmi[(WMI)], a core management technology in the Windows Operating system. | ||
The `wmi` metricset of the Windows module collects metrics via link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/about-wmi[Windows Management Instrumentation (WMI)], a core management technology in the Windows Operating system. | ||
|
||
By leveraging WMI Query Language (WQL), this metricset allows you to extract detailed | ||
system information and metrics to monitor the health and performance of Windows | ||
Systems. | ||
|
||
This metricset leverages the link:https://github.com/microsoft/wmi[Microsoft WMI], library a | ||
convenient wrapper around the link:https://github.com/go-ole[GO-OLE] library which allows to | ||
invoke the WMI Api. | ||
This metricset leverages the link:https://github.com/microsoft/wmi[Microsoft WMI] library, a | ||
convenient wrapper around the link:https://github.com/go-ole[Go-OLE] library. This allows invoking the | ||
link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/scripting-api-for-wmi[Scripting API for WMI]. | ||
|
||
[float] | ||
=== WMI Query Language (WQL) Support | ||
|
||
This metricset supports the execution of link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/wql-sql-for-wmi[WQL] queries, a SQL-like query language for retrieving information from WMI namespaces. | ||
|
||
As of now, we only support and execute queries with `SELECT`, `FROM` and `WHERE` clauses. | ||
Currently, the metricset supports queries with `SELECT`, `FROM` and `WHERE` clauses. | ||
|
||
NOTE: When working with WMI queries, it is the user's responsibility to ensure that queries are safe, efficient, and do not cause unintended side effects. A notorious example of a problematic WMI class is Win32_Product. Read more in link:https://support.microsoft.com/kb/974524[Windows Documentation]. | ||
|
||
[float] | ||
[[wmi-arbitrator-and-query-execution]] | ||
==== WMI Arbitrator and Query Execution | ||
|
||
Query execution is managed by the underlying WMI Framework, specifically the link:https://learn.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/new-wmi-arbitrator-behavior-in-windows-server[WMI Arbitrator]. | ||
The Arbitrator is responsible for: | ||
|
||
- Scheduling and controlling query execution | ||
- Throttling or stopping queries based on system resource availability and conditions | ||
|
||
There is no way to directly stop a query once it has started. To prevent Metricbeat from waiting indefinitely for a query to return a result or fail, Metricbeat has a timeout mechanism that stops waiting for query results after a specified timeout. This is controlled by the `wmi.warning_threshold` setting. | ||
|
||
NOTE: While Metricbeat stops waiting for the result, the underlying WMI query may continue running until the WMI Arbitrator decides to stop execution. | ||
|
||
|
||
[float] | ||
=== Configuration | ||
|
||
[source,yaml] | ||
---- | ||
- module: windows | ||
metricsets: ["wmi"] | ||
period: 60s | ||
namespace: "root\\cimv2" # Namespace | ||
queries: | ||
- class: Win32_OperatingSystem | ||
fields: | ||
- FreePhysicalMemory | ||
- FreeSpaceInPaginFiles | ||
- NumberOfUsers | ||
# Where Clasue | ||
where: "" | ||
period: 10m | ||
wmi: | ||
namespace: "root\\cimv2" # Default Namespace | ||
warning_threshold: 10m | ||
include_queries: true | ||
include_null_properties: false | ||
include_empty_strings_properties: false | ||
queries: | ||
- class: Win32_OperatingSystem | ||
properties: | ||
- FreePhysicalMemory | ||
- FreeSpaceInPagingFiles | ||
- NumberOfUsers | ||
where: "" | ||
- class: Win32_PowerPlan | ||
properties: [] | ||
where: "IsActive = True" | ||
namespace: "root\\cimv2\\power" # Overwrites the module namespace in this query | ||
---- | ||
|
||
*`wmi.namespace`*:: | ||
The default WMI namespace used for queries. This can be overridden per query. | ||
The default is `root\cimv2`. | ||
|
||
*`wmi.warning_threshold`*:: The time threshold after which Metricbeat will stop | ||
waiting for the query result and return control to the main flow of the program. | ||
A warning is logged indicating that the query execution has exceeded the threshold. | ||
The default is equal to the period. See <<wmi-arbitrator-and-query-execution, WMI Arbitrator and Query Execution>> | ||
for more details. | ||
|
||
*`wmi.include_queries`*:: If set to `true` the metricset includes the query in the output document. The default value is `false`. | ||
|
||
*`wmi.include_null_properties`*:: If set to `true` the metricset includes the properties that have null value in the output document. | ||
properties that have a `null` value in the output document. The default value is `false`. | ||
|
||
*`wmi.include_empty_string_properties`*:: A boolean option that causes the metricset to include | ||
the properties that are empty string. The default value is `false`. | ||
|
||
*`wmi.queries`*:: The list of queries to execute. The list cannot be empty. See <<query-configuration, Query Configuration>> for the format of the queries. | ||
herrBez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[float] | ||
[[query-configuration]] | ||
==== Query Configuration | ||
|
||
Each item in the `queries` list specifies a wmi query to perform. | ||
|
||
*`class`*:: The wmi class. In the query it specifies the `FROM` clause. Required | ||
|
||
*`properties`*:: List of properties to return. In the query it specifies the `SELECT` clause. Set it to the empty list (default value) to retrieve all available properties. | ||
|
||
*`where`*:: The where clause. In the query it specifies the `WHERE` clause. Read more about the format link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/where-clause[in the Windows Documentation]. | ||
|
||
*`namespace`*:: The WMI Namespace for this particular query (it overwrites the metricset's `namespace` value) | ||
|
||
[float] | ||
===== Example | ||
|
||
Example WQL Query: | ||
|
||
[source,sql] | ||
---- | ||
SELECT Name, ProcessId, WorkingSetSize | ||
FROM Win32_Process | ||
WHERE Name = 'lsass.exe' AND WorkingSetSize > 104857600 | ||
---- | ||
|
||
Equivalent YAML Configuration: | ||
|
||
[source,yaml] | ||
---- | ||
- class: Win32_Process | ||
properties: | ||
- Name | ||
- ProcessId | ||
- WorkingSetSize | ||
where: "Name = 'lsass.exe' AND WorkingSetSize > 104857600" | ||
---- | ||
|
||
|
||
[float] | ||
=== Best Practices | ||
|
||
- Test your queries in isolation using the `Get-CimInstance` PowerShell cmdlet or the WMI Explorer. | ||
|
||
- Ensure that `wmi.warning_threshold` is **less than or equal to** the module's `period`. | ||
This prevents starting intentionally multiple executions of the same query. | ||
|
||
- Set up alerts in Metricbeat logs for timeouts and empty query results. If a query frequently times out or returns no data, investigate the cause to prevent missing critical information. | ||
|
||
- [Advanced] Collect WMI-Activity Operational Logs to correlate with Metricbeat WMI warnings. | ||
|
||
|
||
[float] | ||
=== Compatibility | ||
|
||
This module has been tested on the following platform: | ||
|
||
- Operating System: Microsoft Windows Server 2019 Datacenter | ||
- Architecture: x86 | ||
- Architecture: x64 | ||
|
||
Other Windows versions and architectures may also work but have not been explicitly tested. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refresh mymind on why we are moving to 10m ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, we had an internal conversion with @strawgate about that manner. We want to basically discourage having too short periods because WMI may be pretty heavy on the system.