parent
5f5e87b596
commit
a49e37a2a6
|
|
@ -28,9 +28,6 @@ var (
|
||||||
maxMetricKeyLen = 250
|
maxMetricKeyLen = 250
|
||||||
)
|
)
|
||||||
|
|
||||||
var counts map[string]string
|
|
||||||
var sent = 0
|
|
||||||
|
|
||||||
// Dynatrace Configuration for the Dynatrace output plugin
|
// Dynatrace Configuration for the Dynatrace output plugin
|
||||||
type Dynatrace struct {
|
type Dynatrace struct {
|
||||||
URL string `toml:"url"`
|
URL string `toml:"url"`
|
||||||
|
|
@ -38,6 +35,8 @@ type Dynatrace struct {
|
||||||
Prefix string `toml:"prefix"`
|
Prefix string `toml:"prefix"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
Timeout internal.Duration `toml:"timeout"`
|
Timeout internal.Duration `toml:"timeout"`
|
||||||
|
State map[string]string
|
||||||
|
SendCounter int
|
||||||
|
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
||||||
|
|
@ -117,6 +116,8 @@ func (d *Dynatrace) normalize(s string, max int) (string, error) {
|
||||||
normalizedString = normalizedString[:len(normalizedString)-1]
|
normalizedString = normalizedString[:len(normalizedString)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalizedString = strings.ReplaceAll(normalizedString, "..", "_")
|
||||||
|
|
||||||
if len(normalizedString) == 0 {
|
if len(normalizedString) == 0 {
|
||||||
return "", fmt.Errorf("error normalizing the string: %s", s)
|
return "", fmt.Errorf("error normalizing the string: %s", s)
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +199,7 @@ func (d *Dynatrace) Write(metrics []telegraf.Metric) error {
|
||||||
var delta float64 = 0
|
var delta float64 = 0
|
||||||
|
|
||||||
// Check if LastValue exists
|
// Check if LastValue exists
|
||||||
if lastvalue, ok := counts[metricID+tagb.String()]; ok {
|
if lastvalue, ok := d.State[metricID+tagb.String()]; ok {
|
||||||
// Convert Strings to Floats
|
// Convert Strings to Floats
|
||||||
floatLastValue, err := strconv.ParseFloat(lastvalue, 32)
|
floatLastValue, err := strconv.ParseFloat(lastvalue, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -213,7 +214,7 @@ func (d *Dynatrace) Write(metrics []telegraf.Metric) error {
|
||||||
fmt.Fprintf(&buf, "%s%s count,delta=%f\n", metricID, tagb.String(), delta)
|
fmt.Fprintf(&buf, "%s%s count,delta=%f\n", metricID, tagb.String(), delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counts[metricID+tagb.String()] = value
|
d.State[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)
|
||||||
|
|
@ -221,11 +222,11 @@ func (d *Dynatrace) Write(metrics []telegraf.Metric) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sent++
|
d.SendCounter++
|
||||||
// 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 d.SendCounter%8640 == 0 {
|
||||||
counts = make(map[string]string)
|
d.State = make(map[string]string)
|
||||||
}
|
}
|
||||||
return d.send(buf.Bytes())
|
return d.send(buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +270,7 @@ func (d *Dynatrace) send(msg []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dynatrace) Init() error {
|
func (d *Dynatrace) Init() error {
|
||||||
counts = make(map[string]string)
|
d.State = make(map[string]string)
|
||||||
if len(d.URL) == 0 {
|
if len(d.URL) == 0 {
|
||||||
d.Log.Infof("Dynatrace URL is empty, defaulting to OneAgent metrics interface")
|
d.Log.Infof("Dynatrace URL is empty, defaulting to OneAgent metrics interface")
|
||||||
d.URL = oneAgentMetricsUrl
|
d.URL = oneAgentMetricsUrl
|
||||||
|
|
@ -298,6 +299,7 @@ func init() {
|
||||||
outputs.Add("dynatrace", func() telegraf.Output {
|
outputs.Add("dynatrace", func() telegraf.Output {
|
||||||
return &Dynatrace{
|
return &Dynatrace{
|
||||||
Timeout: internal.Duration{Duration: time.Second * 5},
|
Timeout: internal.Duration{Duration: time.Second * 5},
|
||||||
|
SendCounter: 0,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue