Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Improve win_perf_counters on non English systems (influxdata#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreF authored and mlinde201 committed Feb 6, 2017
1 parent 2bf6c3c commit 09c31d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ plugins, not just statsd.
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus.
- [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker.
- [#1843](https://github.com/influxdata/telegraf/pull/1843) & [#1668](https://github.com/influxdata/telegraf/issues/1668): Add optional ability to define PID as a tag.
- [#1730](https://github.com/influxdata/telegraf/issues/1730): Fix win_perf_counters not gathering non-English counters.
- [#1730](https://github.com/influxdata/telegraf/issues/1730) & [#2261](https://github.com/influxdata/telegraf/pull/2261): Fix win_perf_counters not gathering non-English counters.
- [#2061](https://github.com/influxdata/telegraf/issues/2061): Fix panic when file stat info cannot be collected due to permissions or other issue(s).
- [#2045](https://github.com/influxdata/telegraf/issues/2045): Graylog output should set short_message field.
- [#1904](https://github.com/influxdata/telegraf/issues/1904): Hddtemp always put the value in the field temperature.
Expand Down
60 changes: 19 additions & 41 deletions plugins/inputs/win_perf_counters/win_perf_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,23 @@ var sanitizedChars = strings.NewReplacer("/sec", "_persec", "/Sec", "_persec",
" ", "_", "%", "Percent", `\`, "")

func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName string, counter string, instance string,
measurement string, include_total bool) {
measurement string, include_total bool) error {

var handle PDH_HQUERY
var counterHandle PDH_HCOUNTER
ret := PdhOpenQuery(0, 0, &handle)
ret = PdhAddCounter(handle, query, 0, &counterHandle)
_ = ret
if m.PreVistaSupport {
ret = PdhAddCounter(handle, query, 0, &counterHandle)
} else {
ret = PdhAddEnglishCounter(handle, query, 0, &counterHandle)
}

// Call PdhCollectQueryData one time to check existance of the counter
ret = PdhCollectQueryData(handle)
if ret != ERROR_SUCCESS {
ret = PdhCloseQuery(handle)
return errors.New("Invalid query for Performance Counters")
}

temp := &item{query, objectName, counter, instance, measurement,
include_total, handle, counterHandle}
Expand All @@ -127,39 +137,6 @@ func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName s
metrics.items = make(map[int]*item)
}
metrics.items[index] = temp
}

func (m *Win_PerfCounters) InvalidObject(exists uint32, query string, PerfObject perfobject, instance string, counter string) error {
if exists == 3221228472 { // PDH_CSTATUS_NO_OBJECT
if PerfObject.FailOnMissing {
err := errors.New("Performance object does not exist")
return err
} else {
fmt.Printf("Performance Object '%s' does not exist in query: %s\n", PerfObject.ObjectName, query)
}
} else if exists == 3221228473 { // PDH_CSTATUS_NO_COUNTER

if PerfObject.FailOnMissing {
err := errors.New("Counter in Performance object does not exist")
return err
} else {
fmt.Printf("Counter '%s' does not exist in query: %s\n", counter, query)
}
} else if exists == 2147485649 { // PDH_CSTATUS_NO_INSTANCE
if PerfObject.FailOnMissing {
err := errors.New("Instance in Performance object does not exist")
return err
} else {
fmt.Printf("Instance '%s' does not exist in query: %s\n", instance, query)

}
} else {
fmt.Printf("Invalid result: %v, query: %s\n", exists, query)
if PerfObject.FailOnMissing {
err := errors.New("Invalid query for Performance Counters")
return err
}
}
return nil
}

Expand Down Expand Up @@ -188,17 +165,18 @@ func (m *Win_PerfCounters) ParseConfig(metrics *itemList) error {
query = "\\" + objectname + "(" + instance + ")\\" + counter
}

var exists uint32 = PdhValidatePath(query)
err := m.AddItem(metrics, query, objectname, counter, instance,
PerfObject.Measurement, PerfObject.IncludeTotal)

if exists == ERROR_SUCCESS {
if err == nil {
if m.PrintValid {
fmt.Printf("Valid: %s\n", query)
}
m.AddItem(metrics, query, objectname, counter, instance,
PerfObject.Measurement, PerfObject.IncludeTotal)
} else {
if PerfObject.FailOnMissing || PerfObject.WarnOnMissing {
err := m.InvalidObject(exists, query, PerfObject, instance, counter)
fmt.Printf("Invalid query: %s\n", query)
}
if PerfObject.FailOnMissing {
return err
}
}
Expand Down

0 comments on commit 09c31d7

Please sign in to comment.