-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Perfmon ignore non existent counters #6432
Changes from 1 commit
b2e86f1
b56740d
8e8b3ad
72ac918
1cb711f
666f838
a359acf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import ( | |
"unicode/utf16" | ||
"unsafe" | ||
|
||
"github.com/elastic/beats/libbeat/logp" | ||
|
||
"github.com/joeshaw/multierror" | ||
"github.com/pkg/errors" | ||
"golang.org/x/sys/windows" | ||
|
@@ -222,7 +224,7 @@ func (q *Query) AddCounter(counterPath string, format Format, instanceName strin | |
|
||
h, err := PdhAddCounter(q.handle, counterPath, 0) | ||
if err != nil { | ||
return errors.Wrapf(err, `failed to add counter (path="%v")`, counterPath) | ||
return err | ||
} | ||
|
||
wildcard := wildcardRegexp.MatchString(counterPath) | ||
|
@@ -314,7 +316,7 @@ type PerfmonReader struct { | |
executed bool // Indicates if the query has been executed. | ||
} | ||
|
||
func NewPerfmonReader(config []CounterConfig) (*PerfmonReader, error) { | ||
func NewPerfmonReader(config PerfmonConfig) (*PerfmonReader, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function NewPerfmonReader should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function NewPerfmonReader should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function NewPerfmonReader should have comment or be unexported |
||
query, err := NewQuery("") | ||
if err != nil { | ||
return nil, err | ||
|
@@ -326,7 +328,7 @@ func NewPerfmonReader(config []CounterConfig) (*PerfmonReader, error) { | |
measurement: map[string]string{}, | ||
} | ||
|
||
for _, counter := range config { | ||
for _, counter := range config.CounterConfig { | ||
var format Format | ||
switch counter.Format { | ||
case "float": | ||
|
@@ -335,8 +337,14 @@ func NewPerfmonReader(config []CounterConfig) (*PerfmonReader, error) { | |
format = LongFormat | ||
} | ||
if err := query.AddCounter(counter.Query, format, counter.InstanceName); err != nil { | ||
if config.IgnoreNECounters { | ||
if err == PDH_CSTATUS_NO_COUNTER { | ||
logp.Info(`ignore non existent counter (path="%v")`, counter.Query) | ||
continue | ||
} | ||
} | ||
query.Close() | ||
return nil, err | ||
return nil, errors.Wrapf(err, `failed to add counter (path="%v")`, counter.Query) | ||
} | ||
|
||
r.instanceLabel[counter.Query] = counter.InstanceLabel | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,11 @@ type CounterConfig struct { | |
Format string `config:"format"` | ||
} | ||
|
||
type PerfmonConfig struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type PerfmonConfig should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type PerfmonConfig should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type PerfmonConfig should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type name will be used as perfmon.PerfmonConfig by other packages, and that stutters; consider calling this Config |
||
IgnoreNECounters bool `config:"perfmon.ignore_non_existent_counters"` | ||
CounterConfig []CounterConfig `config:"perfmon.counters" validate:"required"` | ||
} | ||
|
||
func init() { | ||
if err := mb.Registry.AddMetricSet("windows", "perfmon", New); err != nil { | ||
panic(err) | ||
|
@@ -36,9 +41,7 @@ type MetricSet struct { | |
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
cfgwarn.Beta("The perfmon metricset is beta") | ||
|
||
config := struct { | ||
CounterConfig []CounterConfig `config:"perfmon.counters" validate:"required"` | ||
}{} | ||
config := PerfmonConfig{} | ||
|
||
if err := base.Module().UnpackConfig(&config); err != nil { | ||
return nil, err | ||
|
@@ -57,7 +60,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | |
|
||
} | ||
|
||
reader, err := NewPerfmonReader(config.CounterConfig) | ||
reader, err := NewPerfmonReader(config) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "initialization failed") | ||
} | ||
|
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.
Any other way instead of using
Sleep
here? It makes the test suite much slower and has always potential to break.