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

Fixed json serialization for OpenTSDB http output #1793

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions plugins/outputs/opentsdb/opentsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
tags := cleanTags(m.Tags())

for fieldName, value := range m.Fields() {
metricValue, buildError := buildValue(value)
if buildError != nil {
fmt.Printf("OpenTSDB: %s\n", buildError.Error())
switch value.(type) {
case int64:
case uint64:
case float64:
default:
if o.Debug {
fmt.Printf("OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
}
continue
}

Expand All @@ -120,7 +125,7 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
o.Prefix, m.Name(), fieldName)),
Tags: tags,
Timestamp: now,
Value: metricValue,
Value: value,
}

if err := http.sendDataPoint(metric); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/opentsdb/opentsdb_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type HttpMetric struct {
Metric string `json:"metric"`
Timestamp int64 `json:"timestamp"`
Value string `json:"value"`
Value interface{} `json:"value"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain this? how was this working before if every value was being sent as a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sparrc The OpenTSDB API is a bit loose. It says it doesn't accept string values but it does accept numbers quoted or not. So that is why it is working. Although the API was returning errors for string(characters) values it did process all metrics compared to the telnet API which just bail out at the first error. When you use tools between telegraf and OpenTSDB and they are more strict, it can cause problems so this is why I am making the change.

Tags map[string]string `json:"tags"`
}

Expand Down