-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
win_perf_counters: New option "Expand" expands wildcards in counter definitions. #2336
Conversation
…tion expands wildcards in ObjectName, Instances and Counter.
I think this may solve #1291 @TheFlyingCorpse @discoduck2x could you review? |
My change only expands wildcards and therefore allows to cover wider selection of counters with a compact config entry. It solves part of #1291. Apart from wildcards the #1291 also addresses another issue - currently missing periodical "refresh" of the set of counters monitored by Telegeraf. I see the "refresh" thing as a separate option in the counter definition, and it should be implemented on a separate pull request, |
@o7g8 did you know if PdhExpandCounterPath use localized name or English name for the counter ? I ask this regarding #2261 which allow to use the same name (English name) on all system. Microsoft documentation is not always clear about this, but PdhExpandCounterPath doesn't require localized name to work ? If yes, it may disallow to use this option on non-English system as PdhExpandCounterPath will require localized name and later PdhAddEnglishCounter will require an English name. |
@PierreF , thank you for your comment! Here is the documentation describing handling of localized names:
BTW there is another thing which I've just noticed and which is also important - the PdhExpandCounterPath doesn't support partial wildcards! I will change the code and will use PdhExpandWildCardPath instead of PdhExpandCounterPath, because it more flexible and allows partial wildcrads (on post-Vista systems). Seems like my code requires some more work for non-English systems. |
I have replaced
But surprisingly it doesn't expand following obvious queries with partial wildcards in Counters part:
From the experiments I conclude that the @PierreF I haven't tried the approach with the call to PdhGetCounterInfo, quoted in my previous message. It requires allocation of PDH_COUNTER_INFO structure, which looks a bit scary. |
This looks good to me! |
@sparrc , sorry missed the notify for the latest status on this one , will test asap and get back ! |
@sparrc @TheFlyingCorpse can i find this commit in a binary somewhere? doesnt seem to be any nightly builds available for windows. |
@PierreF could you provide a final review on this? |
One issue: from my understanding this will not works on non-English Windows if we don't set PreVistaSupport = true. PdhExpandWildCardPath seems to take localized name and later (if PreVistaSupport is False) we use PdhAddEnglishCounter. I think we should write in README that when expand is true, counter need to use localized name and it would be great to change the "if m.PreVistaSupport" to include an "or PerfObject.Expand" so when Expand is enabled we use PdhAddCounter instead of PdhAddEnglishCounter. That being said, while testing I got the following error:
Configuration used:
|
@PierreF could you remind me why we ever use "PdhAddEnglishCounter"? Why can't we just always use PdhAddCounter? |
@sparrc Because with PdhAddCounter use need localized name, which means you can not provide one configuration file for all systems. You need one configuration per localization. |
stringLine := UTF16PtrToString(&buf[0]) | ||
for stringLine != "" { | ||
strings = append(strings, stringLine) | ||
nextLineStart += len(stringLine) + 1 |
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.
Pretty sure that +1 should not be here.
If your string has a length of 1 character, the next string is one bytes later, not 1+1 bytes later :)
And this is very likely my issue with panic: runtime error
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.
@PierreF The strings are NULL terminated, so that +1 is for hopping over that one I guess.
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 looks very fishy to me, the length of stringLine
tells us nothing about the offset into buf, because buf contains utf16 while stringLine contains utf8.
I see....I think I misunderstood how that worked. @PierreF In that case, why do we ever use PdhAddCounter? Is it unreasonable to ask users in other countries to use the English names? From what I can tell they are fairly similar... |
Yes, I think that too that PdhAddEnglishCounter should be always used.
That seems reasonable (as long as we wrote in README that currently Expand require localized name as in my previous comment). But it could be a good idea to support only English name and properly implements #2336 (comment) |
A note on the English name. some environments likely use only native language. forcing use of the english counter names can be a negative impact of forcing the removal of the localized alternative (pre-vista). |
I would also be interested in a Windows binary nightly build on this. |
Hello, I have merged o7g8's branch into current master and tested on Windows 10 and Windows Server 2016. It seems to be working just fine. Is it possible to have this PR merged? I could open a new PR with the merges and resolved conflicts if necessary. |
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 is probably a stupid question, but what would happen if we just always treated it as if expand was enabled?
stringLine := UTF16PtrToString(&buf[0]) | ||
for stringLine != "" { | ||
strings = append(strings, stringLine) | ||
nextLineStart += len(stringLine) + 1 |
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 looks very fishy to me, the length of stringLine
tells us nothing about the offset into buf, because buf contains utf16 while stringLine contains utf8.
var buf []uint16 | ||
ret := PdhExpandWildCardPath(query, nil, &bufSize) | ||
for ret == PDH_MORE_DATA { | ||
buf = make([]uint16, bufSize) |
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 code does not seem defensive enough to me. Can bufSize be zero here, if so then the next line will panic. What if ret is not PDH_MORE_DATA at least once, then we will try to index it in UTF16ToStringArray and panic. In general we need to check anything that crosses an application boundary before we can assume anything about it.
@danielnelson Hi, sorry for the delay. I agree with you that we should always treat that expand is enabled. If we always expand the paths, then it would also make the code that decides if we should add the counter measurement inside Gather() simpler, as if we pre-expand when parsing config we know when inside Gather() that we want this measurement (with the exception of still filtering for _Total). |
This PR has been superseded by #4189 |
The change introduces a new option "Expand" to a definition of Windows counter which allows to expand wildcards in ObjectName, Instance and Counter.
Read "Remarks" in https://msdn.microsoft.com/en-us/library/windows/desktop/aa372605(v=vs.85).aspx about how the wildcards are expanded and how they can be used.
Required for all PRs: