-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Plugin/reader each interval #4332
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
Merged
Merged
Changes from 33 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
e12eced
input plugin that reads files each interval
MrMaxBuilds 08a11d7
change config file
MrMaxBuilds 9c4b522
tweak metric output
MrMaxBuilds 4e24a1b
add grok as a top level parser
MrMaxBuilds ec7f131
add more test files
MrMaxBuilds 504d978
clean up some test cases
MrMaxBuilds 542c030
knock more errors from test files
MrMaxBuilds 554b960
add setparser to reader
MrMaxBuilds 36a23ea
Merge branch 'master' into plugin/reader
MrMaxBuilds f40371e
add init function to reader
MrMaxBuilds 9c84595
add grok as a top level parser, still need README
MrMaxBuilds cc40629
allow for import from plugins/all
MrMaxBuilds 79d9ea4
add docker-image spin up for reader
MrMaxBuilds bbd68b3
docker will spin up
MrMaxBuilds bf7220d
add test file to docker spin up
MrMaxBuilds a931eb1
update DATA_FORMATS_INPUT.MD to include grok
MrMaxBuilds e450b26
remove comments
MrMaxBuilds 001658a
condense telegraf.conf
MrMaxBuilds 7fa27f4
more condensing
MrMaxBuilds 1be2a8e
Formatting and revert Makefile
glinton aa750ec
add reader README.md
MrMaxBuilds 892c95a
update readmes
MrMaxBuilds 04f09d6
grok parser func unexported
MrMaxBuilds 8063b38
address some of Daniel's comments
MrMaxBuilds bfc13a7
incomplete changes to logparser plugin
MrMaxBuilds 67db143
still unfinished logparser changes
MrMaxBuilds 8a9da28
logparser is linked to grok parser
MrMaxBuilds cafa95e
logparser no longer uses seperate grok
MrMaxBuilds c6087ab
add more unit tests to grok parser
MrMaxBuilds e4b6f23
fix unit tests for grok parser
MrMaxBuilds d224673
change logparser unit tests
MrMaxBuilds f52ceeb
test files added for logparser
MrMaxBuilds 285cf0b
Merge branch 'master' into plugin/reader
MrMaxBuilds 0c3ac29
addresses daniel's comments
MrMaxBuilds 74900ed
change parser config names
MrMaxBuilds d0f5389
allow for original config and functionality of logparser
MrMaxBuilds dd778a9
finish daniel's changes
MrMaxBuilds 5449eb7
small change to config
MrMaxBuilds 1f58dd7
Rename reader to file input
danielnelson 2a18ca2
Attempt linking to another plugin
danielnelson 50f49fe
Adjust link to data format docs
danielnelson 08d1397
Rename Reader struct to File
danielnelson 63da4e6
Move measurement option to logparser grok config
danielnelson 88a85a7
Set default data_format to influx
danielnelson 2638186
Add deprecation messages to logparser input
danielnelson 1fe3adb
Fix dev config for file input
danielnelson 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -14,9 +14,8 @@ import ( | |
| "github.com/influxdata/telegraf" | ||
| "github.com/influxdata/telegraf/internal/globpath" | ||
| "github.com/influxdata/telegraf/plugins/inputs" | ||
|
|
||
| "github.com/influxdata/telegraf/plugins/parsers" | ||
| // Parsers | ||
| "github.com/influxdata/telegraf/plugins/inputs/logparser/grok" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -36,9 +35,10 @@ type logEntry struct { | |
|
|
||
| // LogParserPlugin is the primary struct to implement the interface for logparser plugin | ||
| type LogParserPlugin struct { | ||
| Files []string | ||
| FromBeginning bool | ||
| WatchMethod string | ||
| Files []string | ||
| FromBeginning bool | ||
| WatchMethod string | ||
| MeasurementName string `toml:"measurement"` | ||
|
|
||
| tailers map[string]*tail.Tail | ||
| lines chan logEntry | ||
|
|
@@ -49,7 +49,13 @@ type LogParserPlugin struct { | |
|
|
||
| sync.Mutex | ||
|
|
||
| GrokParser *grok.Parser `toml:"grok"` | ||
| GrokParser parsers.Parser `toml:"grok"` | ||
|
|
||
| Patterns []string | ||
| NamedPatterns []string | ||
| CustomPatterns string | ||
| CustomPatternFiles []string | ||
| TimeZone string | ||
| } | ||
|
|
||
| const sampleConfig = ` | ||
|
|
@@ -132,6 +138,21 @@ func (l *LogParserPlugin) Start(acc telegraf.Accumulator) error { | |
|
|
||
| // Looks for fields which implement LogParser interface | ||
| l.parsers = []LogParser{} | ||
| config := &parsers.Config{ | ||
| Patterns: l.Patterns, | ||
| NamedPatterns: l.NamedPatterns, | ||
| CustomPatterns: l.CustomPatterns, | ||
| CustomPatternFiles: l.CustomPatternFiles, | ||
| TimeZone: l.TimeZone, | ||
| DataFormat: "grok", | ||
| } | ||
|
|
||
| var err error | ||
| l.GrokParser, err = parsers.NewParser(config) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| s := reflect.ValueOf(l).Elem() | ||
| for i := 0; i < s.NumField(); i++ { | ||
| f := s.Field(i) | ||
|
|
@@ -152,13 +173,6 @@ func (l *LogParserPlugin) Start(acc telegraf.Accumulator) error { | |
| return fmt.Errorf("logparser input plugin: no parser defined") | ||
| } | ||
|
|
||
| // compile log parser patterns: | ||
| for _, parser := range l.parsers { | ||
| if err := parser.Compile(); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
|
Contributor
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. It looks like we are removing l.parsers, I think this is good but also remove the reflect bit above 156:175 and the field from the LogParserPlugin struct. |
||
| l.wg.Add(1) | ||
| go l.parser() | ||
|
|
||
|
|
@@ -251,8 +265,8 @@ func (l *LogParserPlugin) receiver(tailer *tail.Tail) { | |
| } | ||
| } | ||
|
|
||
| // parser is launched as a goroutine to watch the l.lines channel. | ||
| // when a line is available, parser parses it and adds the metric(s) to the | ||
| // parse is launched as a goroutine to watch the l.lines channel. | ||
| // when a line is available, parse parses it and adds the metric(s) to the | ||
| // accumulator. | ||
| func (l *LogParserPlugin) parser() { | ||
| defer l.wg.Done() | ||
|
|
@@ -269,18 +283,17 @@ func (l *LogParserPlugin) parser() { | |
| continue | ||
| } | ||
| } | ||
| for _, parser := range l.parsers { | ||
| m, err = parser.ParseLine(entry.line) | ||
| if err == nil { | ||
| if m != nil { | ||
| tags := m.Tags() | ||
| tags["path"] = entry.path | ||
| l.acc.AddFields(m.Name(), m.Fields(), tags, m.Time()) | ||
| } | ||
| } else { | ||
| log.Println("E! Error parsing log line: " + err.Error()) | ||
| m, err = l.GrokParser.ParseLine(entry.line) | ||
| if err == nil { | ||
| if m != nil { | ||
| tags := m.Tags() | ||
| tags["path"] = entry.path | ||
| l.acc.AddFields(l.MeasurementName, m.Fields(), tags, m.Time()) | ||
| } | ||
| } else { | ||
| log.Println("E! Error parsing log line: " + err.Error()) | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
I think we need a closing
'''for this below.