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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,6 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add _bucket to histogram metrics in Prometheus Collector {pull}11578[11578]
- Prevent the docker/memory metricset from processing invalid events before container start {pull}11676[11676]
- Change `add_cloud_metadata` processor to not overwrite `cloud` field when it already exist in the event. {pull}11612[11612] {issue}11305[11305]
- Fix panics in vsphere module when certain values where not returned by the API. {pull}9784[9784]
- Fix pod UID metadata enrichment in Kubernetes module. {pull}10081[10081]
- Fix issue that would prevent collection of processes without command line on Windows. {pull}10196[10196]
- Fixed data type for tags field in `docker/container` metricset {pull}10307[10307]
- Fixed data type for tags field in `docker/image` metricset {pull}10307[10307]
- Fixed data type for isr field in `kafka/partition` metricset {pull}10307[10307]
- Fixed data types for various hosts fields in `mongodb/replstatus` metricset {pull}10307[10307]
- Added function to close sql database connection. {pull}10355[10355]
- Fix issue with `elasticsearch/node_stats` metricset (x-pack) not indexing `source_node` field. {pull}10639[10639]
- Migrate docker autodiscover to ECS. {issue}10757[10757] {pull}10862[10862]
- Fix issue in kubernetes module preventing usage percentages to be properly calculated. {pull}10946[10946]
- Fix for not reusable http client leading to connection leaks in Jolokia module {pull}11014[11014]
- Fix parsing error using GET in Jolokia module. {pull}11075[11075] {issue}11071[11071]
- Collect metrics when EC2 instances are not in running state. {issue}11008[11008] {pull}11023[11023]
- Change ECS field cloud.provider to aws. {pull}11023[11023]
- Add documentation about jolokia autodiscover fields. {issue}10925[10925] {pull}10979[10979]
- Add missing aws.ec2.instance.state.name into fields.yml. {issue}11219[11219] {pull}11221[11221]
- Fix ec2 metricset to collect metrics from Cloudwatch with the same timestamp. {pull}11142[11142]
- Fix potential memory leak in stopped docker metricsets {pull}11294[11294]
- Change diskio metrics retrieval method (only for Windows) from wmi query to DeviceIOControl function using the IOCTL_DISK_PERFORMANCE control code {pull}11635[11635]
narph marked this conversation as resolved.
Show resolved Hide resolved

*Packetbeat*
Expand Down
6 changes: 5 additions & 1 deletion metricbeat/module/system/diskio/diskstat_windows_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"syscall"
"unsafe"

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

"github.com/pkg/errors"
"golang.org/x/sys/windows/registry"

Expand All @@ -39,6 +41,7 @@ var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW")
Copy link
Member

Choose a reason for hiding this comment

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

GetLogicalDriveStrings would ideally get added at https://github.com/elastic/go-windows/blob/bb1581babc04d5cb29a2bfa7a9ac6781c730c8dd/kernel32.go#L31 and then we'd let the tooling generate the boilerplate code that wraps the method (via running go generate).

We already did this in gosigar but we're trying to migrate this over to go-windows as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will follow up on that with a new PR

procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW")
logger = logp.NewLogger("diskio")
)

type logicalDrive struct {
Expand Down Expand Up @@ -98,7 +101,7 @@ func ioCounters(names ...string) (map[string]disk.IOCountersStat, error) {
return ret, nil
}

// i0Counter calls syscal func CreateFile to generate a handler then executes the DeviceIoControl func in order to retrieve the metrics.
// ioCounter calls syscal func CreateFile to generate a handler then executes the DeviceIoControl func in order to retrieve the metrics.
func ioCounter(path string) (diskPerformance, error) {
var diskPerformance diskPerformance
var diskPerformanceSize uint32
Expand Down Expand Up @@ -142,6 +145,7 @@ func enablePerformanceCounters() error {
if err = key.SetDWordValue("EnableCounterForIoctl", 1); err != nil {
narph marked this conversation as resolved.
Show resolved Hide resolved
return errors.Errorf("cannot create EnableCounterForIoctl key in the registry in order to enable the performance counters: %s", err)
}
logger.Info("The key with the name EnableCounterForIoctl has been added in the windows registry in order to enable the performance counters")
narph marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand Down