Added feature to allow metrics collection every X iterations in specified objects.
This commit is contained in:
parent
042cf517b2
commit
64ada49377
|
@ -59,6 +59,13 @@ Example: `Counters = ["% Idle Time", "% Disk Read Time", "% Disk Write Time"]`
|
|||
This must be specified for every counter you want the results of,
|
||||
it is not possible to ask for all counters in the ObjectName.
|
||||
|
||||
### GetMetricEvery
|
||||
*Optional*
|
||||
|
||||
This parameter can be used where you only want to read an object on every X iteration, say every 10 iterations of whatever the interval is set for in Telegraf. If Telegraf fetches its data every 10s, it translates to only getting the data for this metric every 100s. Useful if the metric you are obtaining is expensive to get back.
|
||||
|
||||
Example `GetMetricEvery = 10`
|
||||
|
||||
### Measurement
|
||||
*Optional*
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ type perfobject struct {
|
|||
ObjectName string
|
||||
Counters []string
|
||||
Instances []string
|
||||
GetMetricEvery int
|
||||
Measurement string
|
||||
WarnOnMissing bool
|
||||
FailOnMissing bool
|
||||
|
@ -104,15 +105,20 @@ type item struct {
|
|||
objectName string
|
||||
counter string
|
||||
instance string
|
||||
getmetricevery int
|
||||
metriccounter int
|
||||
measurement string
|
||||
include_total bool
|
||||
handle win.PDH_HQUERY
|
||||
counterHandle win.PDH_HCOUNTER
|
||||
}
|
||||
|
||||
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, getmetricevery int,
|
||||
measurement string, include_total bool) {
|
||||
|
||||
var metriccounter int = 1
|
||||
|
||||
var handle win.PDH_HQUERY
|
||||
var counterHandle win.PDH_HCOUNTER
|
||||
ret := win.PdhOpenQuery(0, 0, &handle)
|
||||
|
@ -120,8 +126,9 @@ func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName s
|
|||
|
||||
_ = ret
|
||||
|
||||
temp := &item{query, objectName, counter, instance, measurement,
|
||||
include_total, handle, counterHandle}
|
||||
temp := &item{query, objectName, counter, instance, getmetricevery,
|
||||
metriccounter, measurement, include_total, handle, counterHandle}
|
||||
|
||||
index := len(gItemList)
|
||||
gItemList[index] = temp
|
||||
|
||||
|
@ -190,6 +197,13 @@ func (m *Win_PerfCounters) ParseConfig(metrics *itemList) error {
|
|||
query = "\\" + objectname + "(" + instance + ")\\" + counter
|
||||
}
|
||||
|
||||
var getmetricevery int
|
||||
if PerfObject.GetMetricEvery == 0 {
|
||||
getmetricevery = 1
|
||||
} else {
|
||||
getmetricevery = PerfObject.GetMetricEvery
|
||||
}
|
||||
|
||||
var exists uint32 = win.PdhValidatePath(query)
|
||||
|
||||
if exists == win.ERROR_SUCCESS {
|
||||
|
@ -197,7 +211,8 @@ func (m *Win_PerfCounters) ParseConfig(metrics *itemList) error {
|
|||
fmt.Printf("Valid: %s\n", query)
|
||||
}
|
||||
m.AddItem(metrics, query, objectname, counter, instance,
|
||||
PerfObject.Measurement, PerfObject.IncludeTotal)
|
||||
getmetricevery, PerfObject.Measurement,
|
||||
PerfObject.IncludeTotal)
|
||||
} else {
|
||||
err := m.InvalidObject(exists, query, PerfObject, instance, counter)
|
||||
return err
|
||||
|
@ -271,6 +286,8 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
|
|||
// For iterate over the known metrics and get the samples.
|
||||
for _, metric := range gItemList {
|
||||
// collect
|
||||
if metric.getmetricevery == metric.metriccounter {
|
||||
metric.metriccounter = 1
|
||||
ret := win.PdhCollectQueryData(metric.handle)
|
||||
if ret == win.ERROR_SUCCESS {
|
||||
ret = win.PdhGetFormattedCounterArrayDouble(metric.counterHandle, &bufSize,
|
||||
|
@ -323,7 +340,9 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
|
|||
bufCount = 0
|
||||
bufSize = 0
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
metric.metriccounter++
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue