2018-06-22 09:02:34 +08:00
# Tail Input Plugin
2016-04-23 05:47:26 +08:00
The tail plugin "tails" a logfile and parses each log message.
By default, the tail plugin acts like the following unix tail command:
2021-11-25 02:50:13 +08:00
```shell
2016-04-27 00:43:41 +08:00
tail -F --lines=0 myfile.log
2016-04-23 05:47:26 +08:00
```
2016-04-27 00:43:41 +08:00
- `-F` means that it will follow the _name_ of the given file, so
that it will be compatible with log-rotated files, and that it will retry on
inaccessible files.
2016-04-23 05:47:26 +08:00
- `--lines=0` means that it will start at the end of the file (unless
the `from_beginning` option is set).
2021-11-25 02:50:13 +08:00
see < http: / / man7 . org / linux / man-pages / man1 / tail . 1 . html > for more details.
2016-04-23 05:47:26 +08:00
2022-06-09 05:22:56 +08:00
The plugin expects messages in one of the [Telegraf Input Data
Formats](../../../docs/DATA_FORMATS_INPUT.md).
2016-04-23 05:47:26 +08:00
2022-10-27 03:58:36 +08:00
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md
2021-11-25 02:50:13 +08:00
## Configuration
2016-04-23 05:47:26 +08:00
2022-05-24 21:49:47 +08:00
```toml @sample .conf
2022-04-12 21:29:02 +08:00
# Parse the new lines appended to a file
2016-04-23 05:47:26 +08:00
[[inputs.tail]]
2020-03-28 06:40:08 +08:00
## File names or a pattern to tail.
2016-04-27 00:43:41 +08:00
## 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" -> just tail the apache log file
2021-02-17 05:53:50 +08:00
## "/var/log/log[!1-2]* -> tail files without 1-2
## "/var/log/log[^1-2]* -> identical behavior as above
2016-04-27 00:43:41 +08:00
## See https://github.com/gobwas/glob for more examples
##
files = ["/var/mymetrics.out"]
2020-03-28 06:40:08 +08:00
2016-04-27 00:43:41 +08:00
## Read file from beginning.
2020-03-28 06:40:08 +08:00
# from_beginning = false
2016-12-16 22:01:49 +08:00
## Whether file is a named pipe
2020-03-28 06:40:08 +08:00
# pipe = false
2016-04-27 00:43:41 +08:00
2017-09-12 02:56:04 +08:00
## Method used to watch for file updates. Can be either "inotify" or "poll".
# watch_method = "inotify"
2020-03-28 06:40:08 +08:00
## Maximum lines of the file to process that have not yet be written by the
## output. For best throughput set based on the number of metrics on each
## line and the size of the output's metric_batch_size.
# max_undelivered_lines = 1000
2020-07-08 03:43:32 +08:00
## Character encoding to use when interpreting the file contents. Invalid
## characters are replaced using the unicode replacement character. When set
## to the empty string the data is not decoded to text.
## ex: character_encoding = "utf-8"
## character_encoding = "utf-16le"
## character_encoding = "utf-16be"
## character_encoding = ""
# character_encoding = ""
2016-04-27 00:43:41 +08:00
## Data format to consume.
2017-04-28 05:59:18 +08:00
## Each data format has its own unique set of configuration options, read
2016-04-27 00:43:41 +08:00
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "influx"
2020-09-29 06:06:00 +08:00
2021-04-01 00:06:13 +08:00
## 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.
# path_tag = "path"
2022-03-30 23:00:16 +08:00
## Filters to apply to files before generating metrics
## "ansi_color" removes ANSI colors
# filters = []
2020-09-29 06:06:00 +08:00
## multiline parser/codec
## https://www.elastic.co/guide/en/logstash/2.4/plugins-filters-multiline.html
#[inputs.tail.multiline]
## The pattern should be a regexp which matches what you believe to be an indicator that the field is part of an event consisting of multiple lines of log data.
#pattern = "^\s"
## The field's value must be previous or next and indicates the relation to the
## multi-line event.
#match_which_line = "previous"
2022-04-12 21:29:02 +08:00
## The invert_match can be true or false (defaults to false).
2020-09-29 06:06:00 +08:00
## If true, a message not matching the pattern will constitute a match of the multiline filter and the what will be applied. (vice-versa is also true)
#invert_match = false
2022-11-16 01:58:15 +08:00
## The handling method for quoted text (defaults to 'ignore').
## The following methods are available:
## ignore -- do not consider quotation (default)
## single-quotes -- consider text quoted by single quotes (')
## double-quotes -- consider text quoted by double quotes (")
## backticks -- consider text quoted by backticks (`)
## When handling quotes, escaped quotes (e.g. \") are handled correctly.
#quotation = "ignore"
2022-11-28 23:18:57 +08:00
## The preserve_newline option can be true or false (defaults to false).
## If true, the newline character is preserved for multiline elements,
## this is useful to preserve message-structure e.g. for logging outputs.
#preserver_newline = false
2020-09-29 06:06:00 +08:00
#After the specified timeout, this plugin sends the multiline event even if no new pattern is found to start a new event. The default is 5s.
#timeout = 5s
2016-04-23 05:47:26 +08:00
```
2021-11-25 02:50:13 +08:00
## Metrics
2018-06-22 09:02:34 +08:00
Metrics are produced according to the `data_format` option. Additionally a
tag labeled `path` is added to the metric containing the filename being tailed.
2022-11-16 01:58:15 +08:00
## Example Output
There is no predefined metric format, so output depends on plugin input.