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

Win perf counters expand wildcards #3018

Closed
wants to merge 6 commits into from
Closed

Win perf counters expand wildcards #3018

wants to merge 6 commits into from

Conversation

vtsingaras
Copy link

@vtsingaras vtsingaras commented Jul 14, 2017

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

Resolves conflicts against current master from: #2336

return "\\" + objectname + "(" + instance + ")\\" + counter
}

func expandQuery(query string, expand bool) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi it looks like this could be the solution for #2879 the only thing would be to check if the instance name equals "*" and than expand the query. The expandQuery and formatCounterQuery Method could handle this together.

Copy link
Author

Choose a reason for hiding this comment

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

I will be supplying a new patch today with both the changes you proposed and my comment at #2336

Copy link
Author

Choose a reason for hiding this comment

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

On second thought, we shouldn't only check for equality with '' as the ExpandWildcardPath function expands both counter and instance names and also partial wildcards, such as "chrome".

I will be supplying the first patch shortly, if you could review it and make comments, it would be really helpful.

Gather() now uses PdhGetFormattedCounterValue.

Move character sanitization out of the Gather() function to the ParseConfig stage.
bullshit added a commit to bullshit/telegraf that referenced this pull request Jul 24, 2017
@bullshit
Copy link
Contributor

bullshit commented Jul 24, 2017

Hi @vtsingaras thank you for your work. I created a fork and tried to simplify your logic a little bit. I think that this is all you need or do i miss something on the expand feature?!

// return PDH_MORE_DATA and will not set the bufSize.
bufCount = 0
bufSize = 0
ret = PdhGetFormattedCounterValueDouble(metric.counterHandle, &emptyBuf[0], &counterValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, can you explain why PdhGetFormattedCounterValueDouble don't need the removed code and why you are not sanitze the counter and measurment names?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, the previous code used PdhGetFormattedCounterArrayDouble, my version expands the counter queries to a list of individual counter queries and handle all the removed logic in different parts now. I also sanitize the names in AddItem().

        sanitized_measurement := sanitizedChars.Replace(measurement)
	if sanitized_measurement == "" {
		sanitized_measurement = "win_perf_counters"
	}

	sanitized_counter := sanitizedChars.Replace(counter)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry my mistake


"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/metric"
Copy link
Contributor

Choose a reason for hiding this comment

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

btw do you really need telegraf/metric? I'm getting an unused import error

Copy link
Author

Choose a reason for hiding this comment

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

Nope, it seems this import was inserted by my IDE prior to committing.

@vtsingaras
Copy link
Author

@bullshit I'm currently on vacation with no access to a PC. Would it be possible for me to answer in detail on saturday/sunday? Thanks for the quick turnaround.

@bullshit
Copy link
Contributor

bullshit commented Jul 25, 2017

@vtsingaras sure no problem, have fun

@vtsingaras
Copy link
Author

vtsingaras commented Jul 31, 2017

@bullshit It seems your fork is missing my latest commit (f96e524)

@bullshit
Copy link
Contributor

bullshit commented Aug 8, 2017

@vtsingaras i know i wanted to start from scratch and do minimum changes to the existing code.
I'm using your code for the last 2 weeks in a test enviroment and it looks good to me.

There is only one thing. For example:

[[inputs.win_perf_counters.object]]
    ObjectName = "Process"
    Counters = ["% Processor Time"]
    Instances = ["*"] 
    Measurement = "testmeasurement"

telegraf is running, everything is ok. When you start chrome after telegraf you will never get a query to this instance. So if you use wildcards in your telegraf configuration we should periodically refresh the handles. I think somebody tried to fix this a while ago #2345 but it was never merged

@danielnelson danielnelson added the area/windows Related to windows plugins (win_eventlog, win_perf_counters, win_services) label Aug 23, 2017
@aventrax
Copy link

Hello @vtsingaras @bullshit , how can I build telefraf for windows with your latest commits? I'm on version 1.4.0 but the issue persists so I would try if possible...
Thanks

@vtsingaras
Copy link
Author

vtsingaras commented Oct 10, 2017

@bullshit Are you already working on it? I can make it reload the counters, add a ClearItems() func and calling ParseConfig again with locking after a configurable interval would be the easiest I think.

@aventrax You can do a go get for the original repo, cd to ..../influxdata/telegraf, change the remote to point to interworkslcoud/telegraf, do a git fetch and checkout this branch and finally do a go build.

Alternatively I can provide you with the build we use here, however take extra care as I don't like distributing binary builds and can guarantee neither safety and/or quality.

@aventrax
Copy link

@vtsingaras many thanks, anyway I do not understand where is interworkscloud:win_perf_counters-expand-wildcards. Is not on github... 😕

@aventrax
Copy link

aventrax commented Nov 7, 2017

@vtsingaras Finally I have been able to checkout that fork and compile it on windows. A little nightmare.
What can I say, it's working. Anyway, now there is another issue. It's not refreshing. Opening one more notepad.exe is not shown on my graphs until I restart Telegraf. Is there any patch for this? I saw #2345 but it seems a little bit old and never merged.....

My config is the following:

    # Process metrics
    ObjectName = "Process"
    Counters = ["% Processor Time","Working Set - Private"]
    Instances = ["notepad*"]
    Measurement = "notepad_processes"```

@aventrax
Copy link

I'm doing other tests.

With this branch the asterisk is working but I noticed that Telegraf does not start if there isn't at least one process active before starting.

# Process metrics
ObjectName = "Process"
Counters = ["% Processor Time","Working Set - Private"]
Instances = ["notepad*"]
Measurement = "notepad_processes"

Here, I must open at least one notepad.exe before Telegraf, otherwise it throws an error and it crashes.

@bullshit Any news regarding the periodic handles refresh?

@bullshit
Copy link
Contributor

hi,
did you try the option "WarnOnMissing=true" ?
Sorry i don't have any news

@danielnelson
Copy link
Contributor

This PR has been superseded by #4189

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/windows Related to windows plugins (win_eventlog, win_perf_counters, win_services)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants