https://docs.fluentd.org/configuration/config-file
rpm, deb, dmg
sudo vi /etc/td-agent/td-agent.conf
gem
sudo vi /etc/fluent/fluent.conf
docker
docker run -ti --rm -v /path/to/dir:/fluentd/etc fluentd -c /fluentd/etc/<conf-file>
- source ⇒ determines the input sources
- match ⇒ determine the output destination
- filter ⇒ determine event processing
- system ⇒ set system-wide configuration
- label ⇒ group the output and filter for internal routing
- @include ⇒ include other files
- input sources are enabled by selecting and configuring the desired input plugins using source directives.
- you may add multiple
source
configurations as required. - each source directive must include a
@type
parameter to specify the input plugin to use.
- The
source
submits events to the Fluentd routing engine. - An event consists of three entities: tag, time and record
tag
⇒ string separated by dots:myapp.aceess
time
⇒ specified by input plugin, must be unix time formatrecord
⇒ json object .
Ex:
# http://<ip>:9880/myapp.access?json={"event":"data"}
tag: myapp.access
time: (current time)
record: {"event":"data"}
- looks for events with matching tags and processes them.
- The most common use of the
match
directive is to output events to other systems. - plugins that correspond to the
match
directive are called output plugins - Each
match
directive must include a match pattern and a@type
parameter
- filter directive has the same syntax as
match
filter
could be chained for processing pipeline.
Input -> filter 1 -> ... -> filter N -> Output
Ex:
# http://this.host:9880/myapp.access?json={"event":"data"}
<source>
@type http
port 9880
</source>
<filter myapp.access>
@type record_transformer
<record>
host_param "#{Socket.gethostname}"
</record>
</filter>
<match myapp.access>
@type file
path /var/log/fluent/access
</match>
1{"event":"data"}
goes to record_transformer
2 record_transformer
filter adds host_param
field to the event
3 {"event":"data","host_param":"webserver1"}
goes to the file
output plugin
most of system-wide configuratoin are also available via cli options
log_level
suppress_repeated_stacktrace
emit_error_log_interval
suppress_config_dump
without_source
process_name
e.g:
<system>
log_level error # equal to -qq cli deployment option
without_source # equal to --without-source cli deployment option
...
</system>
- label groups filter and output for internal routing.
label
reduces the complexity oftag
handling.
e.g
<source>
@type forward
</source>
<source>
@type tail
@label @SYSTEM
</source>
<filter access.**>
@type record_transformer
<record>
...
</record>
</filter>
<match **>
@type elasticsearch
# ...
</match>
<label @SYSTEM>
<filter var.log.middleware.**>
@type grep
# ...
</filter>
<match **>
@type s3
# ...
</match>
</label>
tail
events will be sent to filtergrep
which will match outpputs3
via label@SYSTEM
.forward
events wihch are not labelled will be sent to filerrecord_transformer
wihch will mmatch outputelasticsearch