Improve win_perf_counters on non English systems (#2261)

This commit is contained in:
Pierre Fersing 2017-01-24 21:46:06 +01:00 committed by Cameron Sparr
parent be10b19760
commit a505123e60
2 changed files with 20 additions and 42 deletions

View File

@ -68,7 +68,7 @@ plugins, not just statsd.
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus. - [#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. - [#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. - [#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). - [#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. - [#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. - [#1904](https://github.com/influxdata/telegraf/issues/1904): Hddtemp always put the value in the field temperature.

View File

@ -110,13 +110,23 @@ var sanitizedChars = strings.NewReplacer("/sec", "_persec", "/Sec", "_persec",
" ", "_", "%", "Percent", `\`, "") " ", "_", "%", "Percent", `\`, "")
func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName string, counter string, instance string, 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 handle PDH_HQUERY
var counterHandle PDH_HCOUNTER var counterHandle PDH_HCOUNTER
ret := PdhOpenQuery(0, 0, &handle) ret := PdhOpenQuery(0, 0, &handle)
ret = PdhAddCounter(handle, query, 0, &counterHandle) if m.PreVistaSupport {
_ = ret 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, temp := &item{query, objectName, counter, instance, measurement,
include_total, handle, counterHandle} include_total, handle, counterHandle}
@ -127,39 +137,6 @@ func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName s
metrics.items = make(map[int]*item) metrics.items = make(map[int]*item)
} }
metrics.items[index] = temp 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 return nil
} }
@ -188,17 +165,18 @@ func (m *Win_PerfCounters) ParseConfig(metrics *itemList) error {
query = "\\" + objectname + "(" + instance + ")\\" + counter 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 { if m.PrintValid {
fmt.Printf("Valid: %s\n", query) fmt.Printf("Valid: %s\n", query)
} }
m.AddItem(metrics, query, objectname, counter, instance,
PerfObject.Measurement, PerfObject.IncludeTotal)
} else { } else {
if PerfObject.FailOnMissing || PerfObject.WarnOnMissing { 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 return err
} }
} }