Fix win_perf_counters to collect counters per instance (#4036)

This commit is contained in:
Daniel Nelson 2018-04-30 17:48:45 -07:00 committed by GitHub
parent 54f9e9e133
commit 95d2857ab8
1 changed files with 22 additions and 4 deletions

View File

@ -192,6 +192,14 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
var size uint32 = uint32(unsafe.Sizeof(PDH_FMT_COUNTERVALUE_ITEM_DOUBLE{})) var size uint32 = uint32(unsafe.Sizeof(PDH_FMT_COUNTERVALUE_ITEM_DOUBLE{}))
var emptyBuf [1]PDH_FMT_COUNTERVALUE_ITEM_DOUBLE // need at least 1 addressable null ptr. var emptyBuf [1]PDH_FMT_COUNTERVALUE_ITEM_DOUBLE // need at least 1 addressable null ptr.
type InstanceGrouping struct {
name string
instance string
objectname string
}
var collectFields = make(map[InstanceGrouping]map[string]interface{})
// For iterate over the known metrics and get the samples. // For iterate over the known metrics and get the samples.
for _, metric := range m.itemCache { for _, metric := range m.itemCache {
// collect // collect
@ -231,20 +239,22 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
} }
if add { if add {
fields := make(map[string]interface{})
tags := make(map[string]string) tags := make(map[string]string)
if s != "" { if s != "" {
tags["instance"] = s tags["instance"] = s
} }
tags["objectname"] = metric.objectName tags["objectname"] = metric.objectName
fields[sanitizedChars.Replace(metric.counter)] =
float32(c.FmtValue.DoubleValue)
measurement := sanitizedChars.Replace(metric.measurement) measurement := sanitizedChars.Replace(metric.measurement)
if measurement == "" { if measurement == "" {
measurement = "win_perf_counters" measurement = "win_perf_counters"
} }
acc.AddFields(measurement, fields, tags) var instance = InstanceGrouping{measurement, s, metric.objectName}
if collectFields[instance] == nil {
collectFields[instance] = make(map[string]interface{})
}
collectFields[instance][sanitizedChars.Replace(metric.counter)] = float32(c.FmtValue.DoubleValue)
} }
} }
@ -257,6 +267,14 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
} }
} }
for instance, fields := range collectFields {
var tags = map[string]string{
"instance": instance.instance,
"objectname": instance.objectname,
}
acc.AddFields(instance.name, fields, tags)
}
return nil return nil
} }