tail(輸入插件)
http://docs.fluentd.org/articles/in_tail
tail Input Plugin
The in_tail
Input plugin allows Fluentd to read events from the tail of text files. Its behavior is similar to the tail -F
command.
in_tail
輸入插件允許fluentd從文本文件的尾部讀事件。它的行爲類似於tail-f 命令。
Example Configuration
in_tail
is included in Fluentd’s core. No additional installation process is required. 不需要額外的安裝過程。
<source> type tail path /var/log/httpd-access.log pos_file /var/log/td-agent/httpd-access.log.pos tag apache.access format apache2 </source>
Please see the Config File article for the basic structure and syntax of the configuration file. |
How it Works
- When Fluentd is first configured with
in_tail
, it will start reading from the tail of that log, not the beggining. - Once the log is rotated, Fluentd starts reading the new file from the beggining. It keeps track of the current inode number.
- If
td-agent
restarts, it starts reading from the last position td-agent read before the restart. This position is recorded in the position file specified by the pos_file parameter. - 當Fluentd首先配置in_tail插件時,它將開始從尾部的日誌閱讀,而不是beggining。
-
一旦日誌是動(更新),Fluentd開始從beggining閱讀新文件。它跟蹤當前的inode號。
-
如果
td-agent
重新啓動時,在重啓之前它從td-agent
最後一個位置開始閱讀。這個位置是記錄在指定的位置文件文件pos參數。(說明爲什麼pos的重要性,它必須有)
Parameters
type (required)
The value must be tail
.
path (required)
The paths to read. Multiple paths can be specified, separated by ‘,’.
路徑讀取。可以指定多個路徑,”、“分離。(這就可以說明,你可以同時收集多個log日誌,而不用在重新起一個source)
tag (required)
The tag of the event. 事件tag
format (required)指定日誌的格式
The format of the log. Itis the name of a template or regexp surrounded by ‘/’.
The regexp must have at least one named capture (?<NAME>PATTERN). If the regexp has a capture named ‘time’, it is used as the time of the event. You can specify the time format using the time_format parameter. If the regexp has a capture named ‘tag’, the tag parameter + the captured tag is used as the tag of the event.
The following templates are supported:
- regexp
- 正則表達式
The regexp for the format parameter can be specified. Fluentular is a great website to test your regexp for Fluentd configuration.
apache2
Reads apache’s log file for the following fields: host, user, time, method, path, code, size, referer and agent. This template is analogous to the following configuration:
讀取日誌文件apache的爲以下字段:主機、用戶、時間、方法、路徑、代碼、大小、推薦人和代理。這個模板類似於如下配置:
format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/ time_format %d/%b/%Y:%H:%M:%S %z
syslog 系統記錄
Reads syslog’s output file (e.g. /var/log/syslog) for the following fields: time, host, ident, and message. This template is analogous to the following configuration:
format /^(?<time>[^ ]* [^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?[^\:]*\: *(?<message>.*)$/ time_format %b %d %H:%M:%S
tsv
orcsv
If you use tsv or csv format, please also specify the keys
parameter.
format tsv keys key1, key2, key3 time_key key2
If you specify the time_key
parameter, it will be used to identify the timestamp of the record. The timestamp when Fluentd reads the record is used by default.
time_key
參數,它將被用來確定記錄的時間戳。時間戳是當Fluentd讀取記錄是默認情況下使用的。format csv keys key1, key2, key3 time_key key3
json
One JSON map, per line. This is the most straight forward format :).
format json
The time_key
parameter can also be specified.
format json time_key key3
pos_file (highly recommended)
This parameter is highly recommended. Fluentd will record the position it last read into this file.
pos_file /var/log/td-agent/tmp/access.log.pos
time_format 時間格式
The format of the time field. This parameter is required only if the format includes a ‘time’ capture and it cannot be parsed automatically. Please see Time#strftime for additional information.
時間字段的格式。這個參數是必需的,只是如果格式包含一個“時間”捕獲和它不能自動解析。請看看 Time#strftime瞭解更多信息。
rotate_wait 循環等待 rotating 我感覺翻譯成(更新)更適合
in_tail actually does a bit more than tail -F
itself. When rotating a file, some data may still need to be written to the old file as opposed to the new one.
in_tail takes care of this by keeping a reference to the old file (even after it has been rotated) for some time before transitioning completely to the new file. This helps prevent data designated for the old file from getting lost. By default, this time interval is 5 seconds.
in_tail通過保持一個參考(即使它已更新)對於在完全轉變成新文件之前的一些時間來保護這個舊的文件。這有助於防止數據被指定爲丟失舊文件。默認情況下,這個時間間隔是5秒
The rotate_wait parameter accepts a single integer representing the number of seconds you want this time interval to be.
[2013-03-29 07:21:55.483292] router - pid=14615 tid=7a93 fid=5354 DEBUG -- Request body: {"host":"api.vcap.me","stats":[{"response_latency":0,"request_tags":"BAh7BjoOY29tcG9uZW50SSIUQ2xvdWRDb250cm9sbGVyBjoGRVQ=","response_codes":{"responses_2xx":2},"response_samples":2}]}
time_format %Y-%m-%d %H:%M:%S