-
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
Plugin/reader each interval #4332
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
e12eced
input plugin that reads files each interval
maxunt 08a11d7
change config file
maxunt 9c4b522
tweak metric output
maxunt 4e24a1b
add grok as a top level parser
maxunt ec7f131
add more test files
maxunt 504d978
clean up some test cases
maxunt 542c030
knock more errors from test files
maxunt 554b960
add setparser to reader
maxunt 36a23ea
Merge branch 'master' into plugin/reader
maxunt f40371e
add init function to reader
maxunt 9c84595
add grok as a top level parser, still need README
maxunt cc40629
allow for import from plugins/all
maxunt 79d9ea4
add docker-image spin up for reader
maxunt bbd68b3
docker will spin up
maxunt bf7220d
add test file to docker spin up
maxunt a931eb1
update DATA_FORMATS_INPUT.MD to include grok
maxunt e450b26
remove comments
maxunt 001658a
condense telegraf.conf
maxunt 7fa27f4
more condensing
maxunt 1be2a8e
Formatting and revert Makefile
glinton aa750ec
add reader README.md
maxunt 892c95a
update readmes
maxunt 04f09d6
grok parser func unexported
maxunt 8063b38
address some of Daniel's comments
maxunt bfc13a7
incomplete changes to logparser plugin
maxunt 67db143
still unfinished logparser changes
maxunt 8a9da28
logparser is linked to grok parser
maxunt cafa95e
logparser no longer uses seperate grok
maxunt c6087ab
add more unit tests to grok parser
maxunt e4b6f23
fix unit tests for grok parser
maxunt d224673
change logparser unit tests
maxunt f52ceeb
test files added for logparser
maxunt 285cf0b
Merge branch 'master' into plugin/reader
maxunt 0c3ac29
addresses daniel's comments
maxunt 74900ed
change parser config names
maxunt d0f5389
allow for original config and functionality of logparser
maxunt dd778a9
finish daniel's changes
maxunt 5449eb7
small change to config
maxunt 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# File Input Plugin | ||
|
||
The file plugin updates a list of files every interval and parses the contents | ||
using the selected [input data format](/docs/DATA_FORMATS_INPUT.md). | ||
|
||
Files will always be read in their entirety, if you wish to tail/follow a file | ||
use the [tail input plugin](/plugins/inputs/tail) instead. | ||
|
||
### Configuration: | ||
```toml | ||
[[inputs.file]] | ||
## Files to parse each interval. | ||
## These accept standard unix glob matching rules, but with the addition of | ||
## ** as a "super asterisk". ie: | ||
## /var/log/**.log -> recursively find all .log files in /var/log | ||
## /var/log/*/*.log -> find all .log files with a parent dir in /var/log | ||
## /var/log/apache.log -> only tail the apache log file | ||
files = ["/var/log/apache/access.log"] | ||
|
||
## Data format to consume. | ||
## Each data format has its own unique set of configuration options, read | ||
## more about them here: | ||
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md | ||
data_format = "influx" | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3' | ||
|
||
services: | ||
telegraf: | ||
image: glinton/scratch | ||
volumes: | ||
- ./telegraf.conf:/telegraf.conf | ||
- ../../../../telegraf:/telegraf | ||
- ./json_a.log:/var/log/test.log | ||
entrypoint: | ||
- /telegraf | ||
- --config | ||
- /telegraf.conf |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"parent": { | ||
"child": 3.0, | ||
"ignored_child": "hi" | ||
}, | ||
"ignored_null": null, | ||
"integer": 4, | ||
"list": [3, 4], | ||
"ignored_parent": { | ||
"another_ignored_null": null, | ||
"ignored_string": "hello, world!" | ||
}, | ||
"another_list": [4] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[[inputs.file]] | ||
files = ["/var/log/test.log"] | ||
data_format = "json" | ||
name_override = "json_file" | ||
|
||
[[outputs.file]] | ||
files = ["stdout"] |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package file | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/influxdata/telegraf" | ||
"github.com/influxdata/telegraf/internal/globpath" | ||
"github.com/influxdata/telegraf/plugins/inputs" | ||
"github.com/influxdata/telegraf/plugins/parsers" | ||
) | ||
|
||
type File struct { | ||
Files []string `toml:"files"` | ||
FromBeginning bool | ||
parser parsers.Parser | ||
|
||
filenames []string | ||
} | ||
|
||
const sampleConfig = ` | ||
## Files to parse each interval. | ||
## These accept standard unix glob matching rules, but with the addition of | ||
## ** as a "super asterisk". ie: | ||
## /var/log/**.log -> recursively find all .log files in /var/log | ||
## /var/log/*/*.log -> find all .log files with a parent dir in /var/log | ||
## /var/log/apache.log -> only tail the apache log file | ||
files = ["/var/log/apache/access.log"] | ||
|
||
## The dataformat to be read from files | ||
## Each data format has its own unique set of configuration options, read | ||
## more about them here: | ||
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md | ||
data_format = "influx" | ||
` | ||
|
||
// SampleConfig returns the default configuration of the Input | ||
func (f *File) SampleConfig() string { | ||
return sampleConfig | ||
} | ||
|
||
func (f *File) Description() string { | ||
return "reload and gather from file[s] on telegraf's interval" | ||
} | ||
|
||
func (f *File) Gather(acc telegraf.Accumulator) error { | ||
err := f.refreshFilePaths() | ||
if err != nil { | ||
return err | ||
} | ||
for _, k := range f.filenames { | ||
metrics, err := f.readMetric(k) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, m := range metrics { | ||
acc.AddFields(m.Name(), m.Fields(), m.Tags(), m.Time()) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (f *File) SetParser(p parsers.Parser) { | ||
f.parser = p | ||
} | ||
|
||
func (f *File) refreshFilePaths() error { | ||
var allFiles []string | ||
for _, file := range f.Files { | ||
g, err := globpath.Compile(file) | ||
if err != nil { | ||
return fmt.Errorf("could not compile glob %v: %v", file, err) | ||
} | ||
files := g.Match() | ||
if len(files) <= 0 { | ||
return fmt.Errorf("could not find file: %v", file) | ||
} | ||
|
||
for k := range files { | ||
allFiles = append(allFiles, k) | ||
} | ||
} | ||
|
||
f.filenames = allFiles | ||
return nil | ||
} | ||
|
||
func (f *File) readMetric(filename string) ([]telegraf.Metric, error) { | ||
fileContents, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, fmt.Errorf("E! Error file: %v could not be read, %s", filename, err) | ||
} | ||
return f.parser.Parse(fileContents) | ||
|
||
} | ||
|
||
func init() { | ||
inputs.Add("file", func() telegraf.Input { | ||
return &File{} | ||
}) | ||
} |
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.