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

Use counter time in win perf counters #4267

Merged
merged 11 commits into from
Jun 30, 2018
Prev Previous commit
Next Next commit
Improved error reporting
  • Loading branch information
vlastahajek committed Jun 13, 2018
commit 4f40a2c46700f6d117bece500b456f719fdf4397
12 changes: 10 additions & 2 deletions plugins/inputs/win_perf_counters/win_perf_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
collectFields[instance][sanitizedChars.Replace(metric.counter)] = float32(value)
} else {
//ignore invalid data from as some counters from process instances returns this sometimes
if phderr, ok := err.(*PdhError); ok && phderr.ErrorCode != PDH_INVALID_DATA && phderr.ErrorCode != PDH_CALC_NEGATIVE_VALUE {
if !isKnowError(err) {
return fmt.Errorf("error while getting value for counter %s: %v", metric.counterPath, err)
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
}
} else {
//ignore invalid data from as some counters from process instances returns this sometimes
if phderr, ok := err.(*PdhError); ok && phderr.ErrorCode != PDH_INVALID_DATA && phderr.ErrorCode != PDH_CALC_NEGATIVE_VALUE {
if !isKnowError(err) {
return fmt.Errorf("error while getting value for counter %s: %v", metric.counterPath, err)
}
}
Expand All @@ -369,6 +369,14 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
return nil
}

//returns true if err is an error we count with
func isKnowError(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename this function and redo the comment? I think based on your comment above maybe you could name it isCounterDataError. You can probably remove the comment above if this name is more precise.

if phderr, ok := err.(*PdhError); ok && (phderr.ErrorCode == PDH_INVALID_DATA || phderr.ErrorCode == PDH_CALC_NEGATIVE_VALUE || phderr.ErrorCode == PDH_CSTATUS_INVALID_DATA) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you line wrap this around 78 chars?

return true
}
return false
}

func init() {
inputs.Add("win_perf_counters", func() telegraf.Input {
return &Win_PerfCounters{query: &PerformanceQueryImpl{}, CountersRefreshInterval: internal.Duration{Duration: time.Second * 60}}
Expand Down