-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add Elasticsearch 5.x output #2332
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
648e50b
Add Elasticsearch 5.x output
lpic10 9ea4d6a
Minor change on README.md
lpic10 7e494b5
Use time.Format() instead
lpic10 d1951a8
Fix issue with template generation
lpic10 e0ebc34
Updates to README.md and config sample
lpic10 d786c6b
Return on not supported ES version
lpic10 bf75c21
Fix ES template
lpic10 8f56697
Use UTC for index creation
lpic10 14d6ed2
Small changes
lpic10 866ce6c
Merge branch 'master' of telegraf into es_support
lpic10 2f94c95
Update index template doc
lpic10 8dd92ab
Change field input_plugin to measurement_name
lpic10 959638a
few improvements
lpic10 a6cfae2
Several updates, added timeout on ES connection
lpic10 debe2e9
Change sniffing to false by default and other formatting fixes
lpic10 4506936
Truncate big values before inserting
lpic10 0e07a9b
Attempt to fix issues with ES dynamic field mapping
lpic10 d9ee5d9
Reverting to previous implementation
lpic10 beb9390
Improved tests & README
lpic10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,14 +146,16 @@ func (a *Elasticsearch) Write(metrics []telegraf.Metric) error { | |
m := make(map[string]interface{}) | ||
mfields := make(map[string]interface{}) | ||
|
||
// Elasticsearch/java/json quirks for correct field mapping | ||
// value as integer cannot be bigger than MaxInt64 or smaller than MinInt64; as a float it cannot be bigger than float32 | ||
for k, v := range metric.Fields() { | ||
switch x := v.(type) { | ||
// Truncate values too big/small for Elasticsearch to not complain when creating a dynamic field mapping | ||
case float64: | ||
if (x > 0 && x > math.MaxFloat32) || (x < 0 && x < math.SmallestNonzeroFloat32) { | ||
v = float32(x) | ||
log.Printf("W! Elasticsearch output metric %s truncated (value %v is too big or too small, truncating to %v)", k, x, v) | ||
} | ||
switch { | ||
case v.(float64) > math.MaxInt64: | ||
v = math.MaxInt64 | ||
case v.(float64) < math.MinInt64: | ||
v = math.MinInt64 | ||
default: | ||
v = float32(v.(float64)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casting everything to float32? |
||
} | ||
mfields[k] = v | ||
} | ||
|
@@ -181,7 +183,7 @@ func (a *Elasticsearch) Write(metrics []telegraf.Metric) error { | |
|
||
if res.Errors { | ||
for id, err := range res.Failed() { | ||
log.Printf("E! Elasticsearch indexing failure, id: %d, error: %s", id, err.Error.Reason) | ||
log.Printf("E! Elasticsearch indexing failure, id: %d, error: %s, caused by: %s, %s", id, err.Error.Reason, err.Error.CausedBy["reason"], err.Error.CausedBy["type"]) | ||
} | ||
return fmt.Errorf("W! Elasticsearch failed to index %d metrics", len(res.Failed())) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work if
v
is afloat32
?Not sure I understand how this compiles, since it's comparing a float64 to an int64?