github.com/influxdata/influxdb/v2@v2.7.6/telegraf/plugins/inputs/tail.go (about) 1 package inputs 2 3 import ( 4 "errors" 5 "fmt" 6 "strconv" 7 "strings" 8 ) 9 10 // Tail is based on telegraf Tail plugin. 11 type Tail struct { 12 baseInput 13 Files []string `json:"files"` 14 } 15 16 // PluginName is based on telegraf plugin name. 17 func (t *Tail) PluginName() string { 18 return "tail" 19 } 20 21 // TOML encodes to toml string 22 func (t *Tail) TOML() string { 23 s := make([]string, len(t.Files)) 24 for k, v := range t.Files { 25 s[k] = strconv.Quote(v) 26 } 27 return fmt.Sprintf(`[[inputs.%s]] 28 ## File names or a pattern to tail. 29 ## These accept standard unix glob matching rules, but with the addition of 30 ## ** as a "super asterisk". ie: 31 ## "/var/log/**.log" -> recursively find all .log files in /var/log 32 ## "/var/log/*/*.log" -> find all .log files with a parent dir in /var/log 33 ## "/var/log/apache.log" -> just tail the apache log file 34 ## "/var/log/log[!1-2]* -> tail files without 1-2 35 ## "/var/log/log[^1-2]* -> identical behavior as above 36 ## See https://github.com/gobwas/glob for more examples 37 ## 38 files = [%s] 39 40 ## Read file from beginning. 41 # from_beginning = false 42 43 ## Whether file is a named pipe 44 # pipe = false 45 46 ## Method used to watch for file updates. Can be either "inotify" or "poll". 47 # watch_method = "inotify" 48 49 ## Maximum lines of the file to process that have not yet be written by the 50 ## output. For best throughput set based on the number of metrics on each 51 ## line and the size of the output's metric_batch_size. 52 # max_undelivered_lines = 1000 53 54 ## Character encoding to use when interpreting the file contents. Invalid 55 ## characters are replaced using the unicode replacement character. When set 56 ## to the empty string the data is not decoded to text. 57 ## ex: character_encoding = "utf-8" 58 ## character_encoding = "utf-16le" 59 ## character_encoding = "utf-16be" 60 ## character_encoding = "" 61 # character_encoding = "" 62 63 ## Data format to consume. 64 ## Each data format has its own unique set of configuration options, read 65 ## more about them here: 66 ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 67 data_format = "influx" 68 69 ## Set the tag that will contain the path of the tailed file. If you don't want this tag, set it to an empty string. 70 # path_tag = "path" 71 72 ## multiline parser/codec 73 ## https://www.elastic.co/guide/en/logstash/2.4/plugins-filters-multiline.html 74 #[inputs.tail.multiline] 75 ## The pattern should be a regexp which matches what you believe to be an 76 ## indicator that the field is part of an event consisting of multiple lines of log data. 77 #pattern = "^\s" 78 79 ## This field must be either "previous" or "next". 80 ## If a line matches the pattern, "previous" indicates that it belongs to the previous line, 81 ## whereas "next" indicates that the line belongs to the next one. 82 #match_which_line = "previous" 83 84 ## The invert_match field can be true or false (defaults to false). 85 ## If true, a message not matching the pattern will constitute a match of the multiline 86 ## filter and the what will be applied. (vice-versa is also true) 87 #invert_match = false 88 89 ## After the specified timeout, this plugin sends a multiline event even if no new pattern 90 ## is found to start a new event. The default timeout is 5s. 91 #timeout = 5s 92 `, t.PluginName(), strings.Join(s, ", ")) 93 } 94 95 // UnmarshalTOML decodes the parsed data to the object 96 func (t *Tail) UnmarshalTOML(data interface{}) error { 97 dataOK, ok := data.(map[string]interface{}) 98 if !ok { 99 return errors.New("bad files for tail input plugin") 100 } 101 files, ok := dataOK["files"].([]interface{}) 102 if !ok { 103 return errors.New("not an array for tail input plugin") 104 } 105 for _, fi := range files { 106 t.Files = append(t.Files, fi.(string)) 107 } 108 return nil 109 }