Skip to content
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

Merged
merged 18 commits into from
Apr 26, 2019

Conversation

narph
Copy link
Contributor

@narph narph commented Apr 3, 2019

Replace the current WMI query to get the system/diskio metrics for Windows

(SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk)

with DeviceIOControl Win32 API method using IOCTL_DISK_PERFORMANCE control code.

Fixes: #3798 and #2842

@narph narph requested a review from a team as a code owner April 3, 2019 16:40
@narph narph requested a review from andrewkroh April 3, 2019 16:40
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskio_windows.go Outdated Show resolved Hide resolved
@narph
Copy link
Contributor Author

narph commented Apr 3, 2019

@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.
Would be great to hear your feedback on this.

@exekias exekias added Team:Integrations Label for the Integrations team :Windows review labels Apr 3, 2019
@narph narph added in progress Pull request is currently in progress. and removed review labels Apr 3, 2019
Copy link
Contributor

@ruflin ruflin left a 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?

metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_linux.go Outdated Show resolved Hide resolved
@narph narph added review and removed in progress Pull request is currently in progress. labels Apr 4, 2019
@andrewkroh
Copy link
Member

@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.

@narph narph force-pushed the fix-system-diskio-counters-for-windows branch from fbef30a to 6767dbd Compare April 5, 2019 10:38
@narph narph requested a review from ruflin April 5, 2019 10:39
@narph narph added the Metricbeat Metricbeat label Apr 5, 2019
Copy link
Contributor

@ruflin ruflin left a 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.

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_linux.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_other.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
@narph narph requested a review from ruflin April 5, 2019 14:30
metricbeat/module/system/diskio/diskstat_linux.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
if err != nil || logicalDisks == nil {
return nil, err
}
ret := make(map[string]disk.IOCountersStat, 0)
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//filter by included devices
// filter by included devices

continue
}

var counter, err = iOCounter(drive.UNCPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var counter, err = iOCounter(drive.UNCPath)
counter, err := iOCounter(drive.UNCPath)

metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
metricbeat/module/system/diskio/diskstat_windows_helper.go Outdated Show resolved Hide resolved
Copy link
Member

@andrewkroh andrewkroh left a 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,
Copy link
Member

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.

Copy link
Contributor Author

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.

@narph narph force-pushed the fix-system-diskio-counters-for-windows branch from ed5caf2 to ddc6de1 Compare April 11, 2019 08:36
@narph narph force-pushed the fix-system-diskio-counters-for-windows branch from 032ae2d to 82acba3 Compare April 19, 2019 12:54
@narph narph requested a review from andrewkroh April 23, 2019 09:59
@narph narph requested a review from andrewkroh April 24, 2019 13:25

// CloseSampling stub for linux implementation
func (stat *DiskIOStat) CloseSampling() {
return
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got renamed

@narph narph requested a review from ruflin April 25, 2019 14:43
@narph narph merged commit 9b57261 into elastic:master Apr 26, 2019
@narph narph deleted the fix-system-diskio-counters-for-windows branch April 26, 2019 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metricbeat Metricbeat review Team:Integrations Label for the Integrations team :Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistency of representation diskio from windows and linux
6 participants