Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynatrace Output: change handling of monotonic counters #8159

Merged
merged 59 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b5f2608
added dynatrace client install instructions
Jul 2, 2020
d2c3d57
fixed some minor issues
Jul 14, 2020
72dd44e
added idea to gitignore
Jul 14, 2020
f49ac2a
changed to DT normalized metric and dimension keys
wolfgangB33r Jul 14, 2020
62c6054
changed to DT normalized metric and dimension keys
wolfgangB33r Jul 14, 2020
34d5f56
changed escaping of values to strconv.Quote
wolfgangB33r Jul 14, 2020
8091b28
Merge pull request #1 from dynatrace-oss-contrib/include-dt-plugin
thschue Jul 16, 2020
de0b09f
added oneagent support
Jul 20, 2020
9c4f3d7
adapted handling for oneagent
Jul 21, 2020
6ae8014
removed debug output
Jul 21, 2020
3aa5d94
Merge pull request #2 from dynatrace-oss-contrib/add-oneagent
thschue Jul 23, 2020
02f560c
fixed normalization for fields, if they start with a digit
Jul 24, 2020
795e3c5
Merge branch 'master' of github.com:influxdata/telegraf
Jul 27, 2020
fb56fcf
fixed normalization
Jul 30, 2020
0e6a347
changed package name
Jul 30, 2020
fc95083
added readme information about direct OneAgent ingest endpoint
Aug 7, 2020
5087a01
added a metric name prefix setting
wolfgangB33r Aug 7, 2020
c4284f7
Merge branch 'master' of github.com:influxdata/telegraf
Aug 10, 2020
9e7dccf
fmtted file
Aug 10, 2020
91e26d9
changed doc
Aug 11, 2020
b783f3a
Update plugins/outputs/dynatrace/dynatrace.go
thschue Aug 12, 2020
38a05fd
Apply suggestions from code review
thschue Aug 12, 2020
a273e62
added requested changes
Aug 12, 2020
de2728f
changed log output
Aug 12, 2020
72b0bc0
changed tls configuration
Aug 12, 2020
f75f254
adapted tests
Aug 12, 2020
72c2418
fmtted file
Aug 12, 2020
869cda4
fixed tests
Aug 12, 2020
9f16099
fixed tag order and added encoding checks in all tests
wolfgangB33r Aug 12, 2020
2167b54
changed formatting
wolfgangB33r Aug 12, 2020
09a8523
Update README.md
mikopp Aug 17, 2020
34fb52f
Merge branch 'master' of github.com:influxdata/telegraf
Aug 17, 2020
c7b1071
Merge pull request #3 from mikopp/patch-2
thschue Aug 17, 2020
fb6c59a
Update README.md
mikopp Aug 17, 2020
1f9fe16
Update README.md
mikopp Aug 17, 2020
42afe19
Update README.md
thschue Aug 17, 2020
c213477
Update README.md
thschue Aug 17, 2020
ca3297f
Update README.md
thschue Aug 17, 2020
74a9148
Merge pull request #4 from mikopp/patch-3
thschue Aug 17, 2020
43dafea
Update README.md
thschue Aug 17, 2020
6edda7e
Update README.md
thschue Aug 17, 2020
0faf5c4
Update README.md
thschue Aug 17, 2020
bf35e34
Update README.md
thschue Aug 17, 2020
231878a
Update README.md
mikopp Aug 17, 2020
0687eaf
Merge pull request #5 from mikopp/patch-4
thschue Aug 17, 2020
ceb4221
Update README.md
thschue Aug 17, 2020
eeb6bed
removed InsecureSkipVerify from struct as it is part of github.com/in…
Aug 20, 2020
4ae0062
Merge branch 'master' of github.com:influxdata/telegraf
Aug 20, 2020
99b3905
Small Doc change
Aug 20, 2020
43b35f2
go fmtted file
Aug 20, 2020
6fdc281
Added dash to AllowedCharList
Sep 7, 2020
1067ad9
Changed Handling of Monotonic Counters
Sep 21, 2020
d30a3b0
Merge branch 'master' of github.com:influxdata/telegraf
Sep 21, 2020
f6b3fb3
Update plugins/outputs/dynatrace/README.md
thschue Sep 21, 2020
a105de5
added delta value support for monotonic count metric types
wolfgangB33r Sep 24, 2020
30f6cac
deleted out.txt file
wolfgangB33r Sep 24, 2020
65fb0af
Merge branch 'master' of github.com:influxdata/telegraf
Sep 24, 2020
90a71f7
added a global state flush interval to prevent any long running memor…
wolfgangB33r Sep 25, 2020
5264a36
Merge branch 'master' of github.com:influxdata/telegraf
Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/outputs/dynatrace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ You will also need to configure an API token for secure access. Find out how to

## Requirements

You will either need a Dynatrace OneAgent (version 1.201 or higher) installed on the same host as Telegraf; or a Dynatrace environment with version 1.202 or higher. Monotonic counters (e.g. diskio.reads, system.uptime) require release 208 or later.
You will either need a Dynatrace OneAgent (version 1.201 or higher) installed on the same host as Telegraf; or a Dynatrace environment with version 1.202 or higher

## Limitations
Expand Down
44 changes: 32 additions & 12 deletions plugins/outputs/dynatrace/dynatrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ package dynatrace
import (
"bytes"
"fmt"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/outputs"
"io/ioutil"
"math"
"net/http"
Expand All @@ -15,18 +11,26 @@ import (
"strconv"
"strings"
"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/outputs"
)

const (
oneAgentMetricsUrl = "http://127.0.0.1:14499/metrics/ingest"
)

var (
reNameAllowedCharList = regexp.MustCompile("[^A-Za-z0-9.]+")
reNameAllowedCharList = regexp.MustCompile("[^A-Za-z0-9.-]+")
maxDimKeyLen = 100
maxMetricKeyLen = 250
)

var counts map[string]string
var sent = 0

// Dynatrace Configuration for the Dynatrace output plugin
type Dynatrace struct {
URL string `toml:"url"`
Expand Down Expand Up @@ -188,16 +192,31 @@ func (d *Dynatrace) Write(metrics []telegraf.Metric) error {
if err != nil {
continue
}
fmt.Fprintf(&buf, "%s", metricID)
// add the tag string
fmt.Fprintf(&buf, "%s", tagb.String())

// write measured value
fmt.Fprintf(&buf, " %v\n", value)
// write metric id,tags and value
switch metric.Type() {
case telegraf.Counter:
if lastvalue, ok := counts[metricID+tagb.String()]; ok {
// only send a counter if a lastvalue is found in the map
// if last value is found we can calc and send the delta value
if v, err := strconv.ParseFloat(lastvalue, 32); err == nil {
if v2, err := strconv.ParseFloat(value, 32); err == nil {
fmt.Fprintf(&buf, "%s%s count,delta=%f\n", metricID, tagb.String(), v2-v)
}
}
}
// put the current value into the map as last value
counts[metricID+tagb.String()] = value
default:
fmt.Fprintf(&buf, "%s%s %v\n", metricID, tagb.String(), value)
}
}
}
}

sent++
// in typical interval of 10s, we will clean the counter state once in 24h which is 8640 iterations
if sent%8640 == 0 {
counts = make(map[string]string)
}
ssoroka marked this conversation as resolved.
Show resolved Hide resolved
return d.send(buf.Bytes())
}

Expand Down Expand Up @@ -240,6 +259,7 @@ func (d *Dynatrace) send(msg []byte) error {
}

func (d *Dynatrace) Init() error {
counts = make(map[string]string)
if len(d.URL) == 0 {
d.Log.Infof("Dynatrace URL is empty, defaulting to OneAgent metrics interface")
d.URL = oneAgentMetricsUrl
Expand Down