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

Refactored Windows perfmon metricset: replaced method to retrieve counter paths with PdhExpandWildCardPathW, separated code by responsibility, removed unused functions #12212

Merged
merged 21 commits into from
Jun 12, 2019

Conversation

narph
Copy link
Contributor

@narph narph commented May 20, 2019

@narph narph requested a review from a team as a code owner May 20, 2019 20:40
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Nice change, but I think we should split this PR if possible in two or three PRs, specially to make it clearer what is changed code and what was moved.
This will also need some changelog entries.

metricbeat/module/windows/perfmon/zpdh_windows.go Outdated Show resolved Hide resolved
metricbeat/module/windows/perfmon/perfmon_helper.go Outdated Show resolved Hide resolved
metricbeat/module/windows/perfmon/perfmon_helper.go Outdated Show resolved Hide resolved
Copy link
Member

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

Great to see this refactoring happening.

metricbeat/module/windows/perfmon/_meta/docs.asciidoc Outdated Show resolved Hide resolved
metricbeat/module/windows/perfmon/_meta/fields.yml Outdated Show resolved Hide resolved
metricbeat/module/windows/perfmon/pdh_query_windows.go Outdated Show resolved Hide resolved
for path, counter := range q.counters {
_, value, err := PdhGetFormattedCounterValue(counter.handle, counter.format|PdhFmtNoCap100)
if err != nil {
rtn[path] = append(rtn[path], CounterValue{Err: err})
Copy link
Member

Choose a reason for hiding this comment

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

I was reading this line and 116 / 118 a few times. Is rtn[path] always set or could we run into a panic here?

Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be a problem here, appending to a nil array works.

metricbeat/module/windows/perfmon/pdh_query_windows.go Outdated Show resolved Hide resolved
@prakash1243
Copy link

prakash1243 commented Jun 2, 2019

@narph - I have checked out your pull request and built meticbeat package locally to collect Windows Perfmon Counters on a Windows-7 32 bit server, I have added a wild card query to collect Private Bytes across all the processes running, The output seems to be different now:

Configuration:
- instance_label: process_private_bytes measurement_label: process.private.bytes query: '\Process(*)\Private Bytes'

Output:
"metricset": { "name": "perfmon", "module": "windows", "rtt": 32001 }, "event": { "dataset": "windows.perfmon", "duration": 32001800 }, "windows": { "perfmon": { "process_private_bytes": "*", "process": { "private": { "bytes": 0 } } } } }

It doesn't collect the Private Bytes for all the processes, instead it had sent only one document with the process name as '*' . I have also added 'perfmon.append_instance_counter: true' to my windows configuration.
I have been waiting for my issue to get fixed #10660, got to know it would be fixed with this PR, so just did a test and wanted to let you know my findings. Thanks !

@narph
Copy link
Contributor Author

narph commented Jun 3, 2019

@prakash1243, I am getting different results here when testing locally with - instance_label: process_private_bytes measurement_label: process.private.bytes query: '\Process(*)\Private Bytes

},
          "metricset" : {
            "name" : "perfmon"
          },
          "service" : {
            "type" : "windows"
          },
          "windows" : {
            "perfmon" : {
              "process" : {
                "private" : {
                  "bytes" : 2564096.0
                }
              },
              "process_private_bytes" : "winpty-agent"
            }
          },
          "ecs" : {
            "version" : "1.0.0"
          },

Nonetheless, I have added an integration test TestWildcardQueryNoInstanceName in pdh_integration_windows_test.go which should pass, mind giving that one a go?
Can you provide me with the entire windows module config if you are still dealing with this issue.

Regarding perfmon.append_instance_counter , in later conversations (#12212 (comment)) I am pointing out that I would leave this feature out and integrate it in a new PR.

@prakash1243
Copy link

prakash1243 commented Jun 3, 2019

Hi @narph - Here is module config:

`- module: windows
metricsets: [perfmon]
period: 5s
perfmon.counters:

  • instance_label: process_private_bytes
    measurement_label: process.private.bytes
    query: '\Process(*)\Private Bytes'
    `
    Will I be able to get a snapshot build with the latest code changes you have in your PR for the Windows 32 bit (metricbeat.exe)? I can just test and let you know.
    I doubt if am doing something wrong while building the package; since am new to the Go lang. :)
    Please let me know. Thanks !

@prakash1243
Copy link

prakash1243 commented Jun 3, 2019

Hi @narph -
Am getting this error, when I try to build the metricbeat package :(
C:\Users\Admin\go\src\github.com\elastic\beats\metricbeat>go build github.com/elastic/beats/vendor/github.com/DataDog/zstd In file included from ./zstd.h:43:0, from ..\vendor\github.com\DataDog\zstd\zstd.go:4: C:/Users/Admin/Desktop/gcc-5.1.0-tdm-1-core/lib/gcc/mingw32/5.1.0/include/stdint .h:9:26: fatal error: stdint.h: No such file or directory compilation terminated.

Would you mind sharing the snapshot build, which could be a huge help for me to test and let you know my findings. Thanks !

@narph
Copy link
Contributor Author

narph commented Jun 4, 2019

@prakash1243 , I believe you can download a snapshot from one of the latest CI builds here https://beats-ci.elastic.co/job/elastic+beats+master+multijob-package-linux/663/gcsObjects/

@prakash1243
Copy link

prakash1243 commented Jun 4, 2019

@prakash1243 , I believe you can download a snapshot from one of the latest CI builds here https://beats-ci.elastic.co/job/elastic+beats+master+multijob-package-linux/663/gcsObjects/

@narph - does this snapshot builds include the changes you had on this PR?

@narph narph requested review from ruflin and jsoriano and removed request for ruflin June 4, 2019 09:19
Copy link
Member

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

LGTM. It seems this was mostly moving core around.

Could you update the PR description accordingly?

for _, value := range config.CounterConfig {
form := strings.ToLower(value.Format)
switch form {
case "":
case "", "float":
Copy link
Member

Choose a reason for hiding this comment

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

Was this a bug before?

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
metricbeat/module/windows/perfmon/pdh_query_windows.go Outdated Show resolved Hide resolved
metricbeat/module/windows/perfmon/pdh_query_windows.go Outdated Show resolved Hide resolved
@narph narph changed the title Small improvements in perfmon Refactored Windows perfmon metricset: replaced method to retrieve counter paths with PdhExpandWildCardPathW, separated code by responsibility, removed unused functions. Jun 11, 2019
@narph narph changed the title Refactored Windows perfmon metricset: replaced method to retrieve counter paths with PdhExpandWildCardPathW, separated code by responsibility, removed unused functions. Refactored Windows perfmon metricset: replaced method to retrieve counter paths with PdhExpandWildCardPathW, separated code by responsibility, removed unused functions Jun 11, 2019
@narph narph requested a review from andrewkroh June 11, 2019 13:45
@narph
Copy link
Contributor Author

narph commented Jun 12, 2019

jenkins, test this

@narph narph merged commit e3d32af into elastic:master Jun 12, 2019
@narph narph deleted the refactor/perfmon-queries branch June 12, 2019 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Integrations Label for the Integrations team :Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

recovered from panic while fetching 'windows/perfmon' for host '' ERROR in Metricbeats Windows Module
8 participants