-
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
Replace WMI query to get the system/diskio metrics for Windows #11635
Replace WMI query to get the system/diskio metrics for Windows #11635
Conversation
@andrewkroh , based on our recent conversation regarding the WMI query and the relevance of the diskio counters on Windows I have implemented an alternative option to get the raw metrics using DeviceIOControl instead. |
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.
- Could you add a changelog entry?
- Any chance to get some tests for these new methods?
- Could you make hound happy where it makes sense?
@andrewkroh I wonder if some of this code should go in go-sysinfo or one of these repos?
We could expose the low-level Windows API via the https://github.com/elastic/go-windows package. |
fbef30a
to
6767dbd
Compare
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.
I suggest we follow up with a PR extracting the logic into go-windows
but first have it this PR for simplicity.
if err != nil || logicalDisks == nil { | ||
return nil, err | ||
} | ||
ret := make(map[string]disk.IOCountersStat, 0) |
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.
You can drop the 0
parameter.
if len(drive.Name) > 3 { | ||
continue | ||
} | ||
//filter by included devices |
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.
//filter by included devices | |
// filter by included devices |
continue | ||
} | ||
|
||
var counter, err = iOCounter(drive.UNCPath) |
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.
var counter, err = iOCounter(drive.UNCPath) | |
counter, err := iOCounter(drive.UNCPath) |
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.
I ran the unit tests inside the win2012 vagrant VM and they failed.
PS C:\Gopath\src\github.com\elastic\beats\metricbeat\module\system\diskio> go test -v .
=== RUN TestCDriveFilterOnWindowsTestEnv
--- FAIL: TestCDriveFilterOnWindowsTestEnv (0.00s)
diskstat_windows_test.go:40:
Error Trace: diskstat_windows_test.go:40
Error: Should be empty, but was [disk io counters: The system cannot find the file specified.]
Test: TestCDriveFilterOnWindowsTestEnv
diskstat_windows_test.go:41:
Error Trace: diskstat_windows_test.go:41
Error: Not equal:
expected: 1
actual : 0
Test: TestCDriveFilterOnWindowsTestEnv
=== RUN TestAllDrivesOnWindowsTestEnv
--- FAIL: TestAllDrivesOnWindowsTestEnv (0.00s)
diskstat_windows_test.go:52:
Error Trace: diskstat_windows_test.go:52
Error: Should be empty, but was [disk io counters: The system cannot find the file specified.]
Test: TestAllDrivesOnWindowsTestEnv
diskstat_windows_test.go:53:
Error Trace: diskstat_windows_test.go:53
Error: Should be true
Test: TestAllDrivesOnWindowsTestEnv
FAIL
FAIL github.com/elastic/beats/metricbeat/module/system/diskio 0.038s
defer syscall.CloseHandle(hFile) | ||
|
||
err = syscall.DeviceIoControl(hFile, | ||
ioctlDiskPerformance, |
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.
Should we return each of the devices back to their original state when the metricset stops? Like send IOCTL_DISK_PERFORMANCE_OFF
if it was previously off.
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.
As previously discussed, for now it will be enabled as there could be other processes running on the machine that need this performance counter enabled.
As a somewhat workaround we are letting the users know in the logs that we are enabling these performance counters by adding the EnableCounterForIoctl key in the windows registry.
The function disablePerformanceCounters
which will disable there perf counters has been added in the code for testing purposes only.
ed5caf2
to
ddc6de1
Compare
032ae2d
to
82acba3
Compare
|
||
// CloseSampling stub for linux implementation | ||
func (stat *DiskIOStat) CloseSampling() { | ||
return |
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.
not addressed yet but also not an issue ;-)
return false | ||
} | ||
|
||
// filterLogicalDrives should filter CD-ROM type drives based on https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getdrivetypew |
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.
This got renamed
…ub.com/narph/beats into fix-system-diskio-counters-for-windows
Replace the current
WMI
query to get the system/diskio metrics for Windowswith
DeviceIOControl
Win32 API method usingIOCTL_DISK_PERFORMANCE
control code.Fixes: #3798 and #2842