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

Fix instance name in perfmon metricset #22261

Merged
merged 47 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
938e66c
mofidy doc
narph Jul 23, 2020
4daef08
Merge branch 'master' of github.com:elastic/beats
narph Aug 3, 2020
b613178
Merge branch 'master' of github.com:elastic/beats
narph Aug 4, 2020
05364cf
Merge branch 'master' of github.com:elastic/beats
narph Aug 4, 2020
f147c4d
Merge branch 'master' of github.com:elastic/beats
narph Aug 4, 2020
4574718
Merge branch 'master' of github.com:elastic/beats
narph Aug 17, 2020
1e43077
Merge branch 'master' of github.com:elastic/beats
narph Aug 19, 2020
807cf06
Merge branch 'master' of github.com:elastic/beats
narph Aug 24, 2020
2096668
Merge branch 'master' of github.com:elastic/beats
narph Aug 27, 2020
da8ac1f
Merge branch 'master' of github.com:elastic/beats
narph Aug 27, 2020
c2d8930
Merge branch 'master' of github.com:elastic/beats
narph Aug 27, 2020
7bd9e73
Merge branch 'master' of github.com:elastic/beats
narph Aug 31, 2020
6e89a84
Merge branch 'master' of github.com:elastic/beats
narph Aug 31, 2020
bdf21e9
Merge branch 'master' of github.com:elastic/beats
narph Sep 2, 2020
7833687
Merge branch 'master' of github.com:elastic/beats
narph Sep 3, 2020
bbf6178
Merge branch 'master' of github.com:elastic/beats
narph Sep 4, 2020
4ba8817
Merge branch 'master' of github.com:elastic/beats
narph Sep 7, 2020
0cba5dc
Merge branch 'master' of github.com:elastic/beats
narph Sep 8, 2020
b2625ca
Merge branch 'master' of github.com:elastic/beats
narph Sep 8, 2020
5100e6a
Merge branch 'master' of github.com:elastic/beats
narph Sep 9, 2020
a302d31
Merge branch 'master' of github.com:elastic/beats
narph Sep 14, 2020
631d667
Merge branch 'master' of github.com:elastic/beats
narph Sep 15, 2020
35072a5
Merge branch 'master' of github.com:elastic/beats
narph Sep 17, 2020
4b2f87a
Merge branch 'master' of github.com:elastic/beats
narph Sep 22, 2020
f26b533
Merge branch 'master' of github.com:elastic/beats
narph Sep 28, 2020
c61620d
Merge branch 'master' of github.com:elastic/beats
narph Sep 28, 2020
43f90c4
Merge branch 'master' of github.com:elastic/beats
narph Sep 30, 2020
2d28f07
Merge branch 'master' of github.com:elastic/beats
narph Oct 1, 2020
0a42bbe
Merge branch 'master' of github.com:elastic/beats
narph Oct 2, 2020
0bedffe
Merge branch 'master' of github.com:elastic/beats
narph Oct 5, 2020
2eb7142
Merge branch 'master' of github.com:elastic/beats
narph Oct 5, 2020
f9e4522
Merge branch 'master' of github.com:elastic/beats
narph Oct 12, 2020
227bd50
Merge branch 'master' of github.com:elastic/beats
narph Oct 15, 2020
6e39971
Merge branch 'master' of github.com:elastic/beats
narph Oct 19, 2020
0e85625
Merge branch 'master' of github.com:elastic/beats
narph Oct 19, 2020
6770f2d
Merge branch 'master' of github.com:elastic/beats
narph Oct 20, 2020
63ab6a7
Merge branch 'master' of github.com:elastic/beats
narph Oct 26, 2020
6358eb8
Merge branch 'master' of github.com:elastic/beats
narph Oct 27, 2020
8a9c382
Merge branch 'master' of github.com:elastic/beats
narph Oct 28, 2020
70f5f0e
Merge branch 'master' of github.com:elastic/beats
narph Oct 28, 2020
81e66b5
Merge branch 'master' of github.com:elastic/beats
narph Oct 29, 2020
c35f2ed
fix
narph Oct 29, 2020
e8d1052
changelog
narph Oct 29, 2020
6f0f8d0
Merge branch 'master' of github.com:elastic/beats
narph Oct 29, 2020
9c328e4
Merge branch 'master' of github.com:elastic/beats
narph Oct 30, 2020
cf8a818
Merge branch 'master' into perfmon-inst
narph Oct 30, 2020
073a28f
add test
narph Nov 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- [Kubernetes] Remove redundant dockersock volume mount {pull}22009[22009]
- Revert change to report `process.memory.rss` as `process.memory.wss` on Windows. {pull}22055[22055]
- Add a switch to the driver definition on SQL module to use pretty names {pull}17378[17378]
- Fix instance name in perfmon metricset. {issue}22218[22218] {pull}22261[22261]
- Remove io.time from windows {pull}22237[22237]
- Add interval information to `monitor` metricset in azure. {pull}22152[22152]

Expand Down
113 changes: 51 additions & 62 deletions metricbeat/module/windows/perfmon/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,78 +73,23 @@ func NewReader(config Config) (*Reader, error) {
config: config,
}
r.mapCounters(config)
for i, counter := range r.counters {
r.counters[i].ChildQueries = []string{}
childQueries, err := query.GetCounterPaths(counter.QueryName)
if err != nil {
if config.IgnoreNECounters {
switch err {
case pdh.PDH_CSTATUS_NO_COUNTER, pdh.PDH_CSTATUS_NO_COUNTERNAME,
pdh.PDH_CSTATUS_NO_INSTANCE, pdh.PDH_CSTATUS_NO_OBJECT:
r.log.Infow("Ignoring non existent counter", "error", err,
logp.Namespace("perfmon"), "query", counter.QueryName)
continue
}
} else {
query.Close()
return nil, errors.Wrapf(err, `failed to expand counter (query="%v")`, counter.QueryName)
}
}
// check if the pdhexpandcounterpath/pdhexpandwildcardpath functions have expanded the counter successfully.
if len(childQueries) == 0 || (len(childQueries) == 1 && strings.Contains(childQueries[0], "*")) {
// covering cases when PdhExpandWildCardPathW returns no counter paths or is unable to expand and the ignore_non_existent_counters flag is set
if config.IgnoreNECounters {
r.log.Infow("Ignoring non existent counter", "initial query", counter.QueryName,
logp.Namespace("perfmon"), "expanded query", childQueries)
continue
}
return nil, errors.Errorf(`failed to expand counter (query="%v"), no error returned`, counter.QueryName)
}
for _, v := range childQueries {
if err := query.AddCounter(v, counter.InstanceName, counter.Format, len(childQueries) > 1); err != nil {
return nil, errors.Wrapf(err, `failed to add counter (query="%v")`, counter.QueryName)
}
r.counters[i].ChildQueries = append(r.counters[i].ChildQueries, v)
}
_, err := r.getCounterPaths()
if err != nil {
return nil, err
}
return r, nil
}

// RefreshCounterPaths will recheck for any new instances and add them to the counter list
func (re *Reader) RefreshCounterPaths() error {
var newCounters []string
for i, counter := range re.counters {
re.counters[i].ChildQueries = []string{}
childQueries, err := re.query.GetCounterPaths(counter.QueryName)
if err != nil {
if re.config.IgnoreNECounters {
switch err {
case pdh.PDH_CSTATUS_NO_COUNTER, pdh.PDH_CSTATUS_NO_COUNTERNAME,
pdh.PDH_CSTATUS_NO_INSTANCE, pdh.PDH_CSTATUS_NO_OBJECT:
re.log.Infow("Ignoring non existent counter", "error", err,
logp.Namespace("perfmon"), "query", counter.QueryName)
continue
}
} else {
return errors.Wrapf(err, `failed to expand counter (query="%v")`, counter.QueryName)
}
}
newCounters = append(newCounters, childQueries...)
// there are cases when the ExpandWildCardPath will retrieve a successful status but not an expanded query so we need to check for the size of the list
if err == nil && len(childQueries) >= 1 && !strings.Contains(childQueries[0], "*") {
for _, v := range childQueries {
if err := re.query.AddCounter(v, counter.InstanceName, counter.Format, len(childQueries) > 1); err != nil {
return errors.Wrapf(err, "failed to add counter (query='%v')", counter.QueryName)
}
re.counters[i].ChildQueries = append(re.counters[i].ChildQueries, v)
}
}
newCounters, err := re.getCounterPaths()
if err != nil {
return errors.Wrap(err, "failed retrieving counter paths")
}
err := re.query.RemoveUnusedCounters(newCounters)
err = re.query.RemoveUnusedCounters(newCounters)
if err != nil {
return errors.Wrap(err, "failed removing unused counter values")
}

return nil
}

Expand Down Expand Up @@ -184,6 +129,39 @@ func (re *Reader) Close() error {
return re.query.Close()
}

// getCounterPaths func will process the counter paths based on the configuration options entered
func (re *Reader) getCounterPaths() ([]string, error) {
var newCounters []string
for i, counter := range re.counters {
re.counters[i].ChildQueries = []string{}
childQueries, err := re.query.GetCounterPaths(counter.QueryName)
if err != nil {
if re.config.IgnoreNECounters {
switch err {
case pdh.PDH_CSTATUS_NO_COUNTER, pdh.PDH_CSTATUS_NO_COUNTERNAME,
pdh.PDH_CSTATUS_NO_INSTANCE, pdh.PDH_CSTATUS_NO_OBJECT:
re.log.Infow("Ignoring non existent counter", "error", err,
logp.Namespace("perfmon"), "query", counter.QueryName)
continue
}
} else {
return newCounters, errors.Wrapf(err, `failed to expand counter (query="%v")`, counter.QueryName)
}
}
newCounters = append(newCounters, childQueries...)
// there are cases when the ExpandWildCardPath will retrieve a successful status but not an expanded query so we need to check for the size of the list
if err == nil && len(childQueries) >= 1 && !strings.Contains(childQueries[0], "*") {
for _, v := range childQueries {
if err := re.query.AddCounter(v, counter.InstanceName, counter.Format, isWildcard(childQueries, counter.InstanceName)); err != nil {
return newCounters, errors.Wrapf(err, "failed to add counter (query='%v')", counter.QueryName)
}
re.counters[i].ChildQueries = append(re.counters[i].ChildQueries, v)
}
}
}
return newCounters, nil
}

func (re *Reader) getCounter(query string) (bool, PerfCounter) {
for _, counter := range re.counters {
for _, childQuery := range counter.ChildQueries {
Expand Down Expand Up @@ -310,3 +288,14 @@ func replaceUpperCase(src string) string {
return newStr
})
}

// isWildcard function checks if users has configured a wildcard inside the instance configuration option and if the wildcard has been resulted in a valid number of queries
func isWildcard(queries []string, instance string) bool {
if len(queries) > 1 {
return true
}
if len(queries) == 1 && strings.Contains(instance, "*") {
return true
}
return false
}