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

Fix: Filtering out ramdisks in diskio metricset #12829

Merged
merged 5 commits into from Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -146,6 +146,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Reuse connections in PostgreSQL metricsets. {issue}12504[12504] {pull}12603[12603]
- PdhExpandWildCardPathW will not expand counter paths in 32 bit windows systems, workaround will use a different function.{issue}12590[12590]{pull}12622[12622]
- In the elasticsearch/node_stats metricset, if xpack is enabled, make parsing of ES node load average optional as ES on Windows doesn't report load average. {pull}12866[12866]
- Ramdisk is not filtered out when collecting disk performance counters in diskio metricset {issue}12814[12814] {pull}12829[12829]

*Packetbeat*

Expand Down
41 changes: 38 additions & 3 deletions metricbeat/module/system/diskio/diskstat_windows_helper.go
Expand Up @@ -20,9 +20,12 @@
package diskio

import (
"strings"
"syscall"
"unsafe"

windows2 "golang.org/x/sys/windows"

"github.com/elastic/beats/libbeat/logp"

"github.com/pkg/errors"
Expand Down Expand Up @@ -86,7 +89,8 @@ func ioCounters(names ...string) (map[string]disk.IOCountersStat, error) {
var counter diskPerformance
err = ioCounter(drive.UNCPath, &counter)
if err != nil {
return nil, err
logp.Err("Could not return any performance counter values for %s .Error: %v", drive.UNCPath, err)
continue
}
ret[drive.Name] = disk.IOCountersStat{
Name: drive.Name,
Expand Down Expand Up @@ -220,9 +224,40 @@ func isValidLogicalDrive(path string) bool {
}
ret, _, err := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(utfPath)), 0, 0)

//DRIVE_NO_ROOT_DIR = 1 DRIVE_CDROM = 5
if ret == 1 || ret == 5 || err != errorSuccess {
//DRIVE_NO_ROOT_DIR = 1 DRIVE_CDROM = 5 DRIVE_UNKNOWN = 0 DRIVE_RAMDISK = 6
if ret == 1 || ret == 5 || ret == 0 || ret == 6 || err != errorSuccess {
return false
}

//check for ramdisk label as the drive type is fixed in this case
volumeLabel, err := GetVolumeLabel(utfPath)
if err != nil {
return false
}
if strings.ToLower(volumeLabel) == "ramdisk" {
return false
}
return true
}

// GetVolumeLabel function will retrieve the volume label
func GetVolumeLabel(path *uint16) (string, error) {
lpVolumeNameBuffer := make([]uint16, 256)
lpVolumeSerialNumber := uint32(0)
lpMaximumComponentLength := uint32(0)
lpFileSystemFlags := uint32(0)
lpFileSystemNameBuffer := make([]uint16, 256)
err := windows2.GetVolumeInformation(
path,
&lpVolumeNameBuffer[0],
uint32(len(lpVolumeNameBuffer)),
&lpVolumeSerialNumber,
&lpMaximumComponentLength,
&lpFileSystemFlags,
&lpFileSystemNameBuffer[0],
uint32(len(lpFileSystemNameBuffer)))
if err != nil {
return "", err
}
return syscall.UTF16ToString(lpVolumeNameBuffer), nil
}