Dynatrace Output Plugin: Fixed behaviour when state map is cleared (#8251)
This commit is contained in:
parent
7c2c2c5d8b
commit
c85fb585ad
|
|
@ -1,6 +1,6 @@
|
||||||
# Dynatrace Output Plugin
|
# Dynatrace Output Plugin
|
||||||
|
|
||||||
This plugin is sending telegraf metrics to [Dynatrace](www.dynatrace.com). It has two operational modes.
|
This plugin is sending telegraf metrics to [Dynatrace](https://www.dynatrace.com). It has two operational modes.
|
||||||
|
|
||||||
Telegraf minimum version: Telegraf 1.16
|
Telegraf minimum version: Telegraf 1.16
|
||||||
Plugin minimum tested version: 1.16
|
Plugin minimum tested version: 1.16
|
||||||
|
|
|
||||||
|
|
@ -195,17 +195,26 @@ func (d *Dynatrace) Write(metrics []telegraf.Metric) error {
|
||||||
// write metric id,tags and value
|
// write metric id,tags and value
|
||||||
switch metric.Type() {
|
switch metric.Type() {
|
||||||
case telegraf.Counter:
|
case telegraf.Counter:
|
||||||
|
var delta float64 = 0
|
||||||
|
|
||||||
|
// Check if LastValue exists
|
||||||
if lastvalue, ok := counts[metricID+tagb.String()]; ok {
|
if lastvalue, ok := counts[metricID+tagb.String()]; ok {
|
||||||
// only send a counter if a lastvalue is found in the map
|
// Convert Strings to Floats
|
||||||
// if last value is found we can calc and send the delta value
|
floatLastValue, err := strconv.ParseFloat(lastvalue, 32)
|
||||||
if v, err := strconv.ParseFloat(lastvalue, 32); err == nil {
|
if err != nil {
|
||||||
if v2, err := strconv.ParseFloat(value, 32); err == nil {
|
d.Log.Debugf("Could not parse last value: %s", lastvalue)
|
||||||
fmt.Fprintf(&buf, "%s%s count,delta=%f\n", metricID, tagb.String(), v2-v)
|
}
|
||||||
}
|
floatCurrentValue, err := strconv.ParseFloat(value, 32)
|
||||||
|
if err != nil {
|
||||||
|
d.Log.Debugf("Could not parse current value: %s", value)
|
||||||
|
}
|
||||||
|
if floatCurrentValue > floatLastValue {
|
||||||
|
delta = floatCurrentValue - floatLastValue
|
||||||
|
fmt.Fprintf(&buf, "%s%s count,delta=%f\n", metricID, tagb.String(), delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// put the current value into the map as last value
|
|
||||||
counts[metricID+tagb.String()] = value
|
counts[metricID+tagb.String()] = value
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(&buf, "%s%s %v\n", metricID, tagb.String(), value)
|
fmt.Fprintf(&buf, "%s%s %v\n", metricID, tagb.String(), value)
|
||||||
}
|
}
|
||||||
|
|
@ -214,6 +223,7 @@ func (d *Dynatrace) Write(metrics []telegraf.Metric) error {
|
||||||
}
|
}
|
||||||
sent++
|
sent++
|
||||||
// in typical interval of 10s, we will clean the counter state once in 24h which is 8640 iterations
|
// in typical interval of 10s, we will clean the counter state once in 24h which is 8640 iterations
|
||||||
|
|
||||||
if sent%8640 == 0 {
|
if sent%8640 == 0 {
|
||||||
counts = make(map[string]string)
|
counts = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue