Fluentd
Search…
Configuration Parameter Types

Types of Configuration Parameters

Common Options

    default: Specifies the default value for a parameter. If omitted, the
    parameter is required. On startup, Fluentd uses the default value instead if
    the parameter is not configured.
1
# Required parameter: The configuration must have this parameter like 'param1 10'.
2
config_param :param1, :integer
3
4
# Optional parameter: If the configuration doesn't have 'param2', 100 is used.
5
config_param :param2, :integer, default: 100
Copied!
    secret: If true, the parameter will be masked when Fluentd dumps its
    configuration on the standard output on startup.
1
config_param :secret_param, :string, secret: true
Copied!
    deprecated: Specifies the deprecation warning message. If users use this
    parameter in the configuration, they will see the deprecation warning on
    startup.
1
config_param :old_param, :string, deprecated: "Use new_param instead"
Copied!
    obsoleted: Specifies the obsolete error message. If users use this parameter
    in the configuration, Fluentd raises Fluent::ConfigError and stops.
1
config_param :dead_param, :string, obsoleted: "This parameter doesn't work anymore"
Copied!
    alias: Alias for this parameter as a symbol.
    skip_accessor: If true, skip adding accessor to the plugin. For internal
    use only!

Data Types

:string

Defines a string parameter.
Code Example:
1
config_param :name, :string, default: "John Doe", alias: :full_name
2
config_param :password, :string, secret: true
3
4
def configure(conf)
5
super
6
7
log.info(name: @name, password: @password)
8
end
Copied!
Configuration Example:
1
name John Titor
2
password very-secret-password
Copied!

:regexp

Defines a regexp parameter. Since v1.2.0.
Code Example:
1
config_param :pattern, :regexp, default: /^key_/
2
3
def configure(conf)
4
super
5
6
log.info(pattern: @pattern)
7
end
8
9
def filter(tag, time, record)
10
new_record = record.select do |k, v|
11
@pattern.match(k)
12
end
13
new_record
14
end
Copied!
Configuration Example:
1
pattern /^name_/
2
pattern ^name_ # Also support pattern without slashes
Copied!

:integer

Defines an integer parameter.
Code Example:
1
config_param :num_children, :integer, default: 1
2
3
def start
4
super
5
# ...
6
@num_children.times do |n|
7
# do something...
8
end
9
end
Copied!
Configuration Example:
1
num_children 10
Copied!

:float

Defines a float parameter.
Code Example:
1
helpers :timer
2
config_param :interval, :float, default: 0.5
3
4
def start
5
super
6
# ...
7
timer_execute(:in_example, @interval) do
8
# do something periodically
9
end
10
end
Copied!
Configuration Example:
1
interval 1.5
Copied!

:size

Defines a size parameter in bytes.
Available suffixes: { k, m, g, t } (ignore case)
Code Example:
1
config_param :limit, :size
2
3
def do_something
4
raise "overflow!" if @limit < current
5
# ...
6
end
Copied!
Configuration Example:
1
limit 10 # 10 byte
2
limit 10k # 10240 byte
3
limit 10m # 10485760 byte
4
limit 10g # 10737418240 byte
5
limit 10t # 10995116277760 byte
Copied!
Configuration Example:
1
limit 10m
Copied!

:time

Defines the length of the time parameter.
Available suffixes: { s, m, h, d } (lower case only).
If omitted, to_f is applied to the value which converts it to seconds.
Code Example:
1
config_param :interval, :time
2
3
def start
4
timer_execute(:in_example, @interval) do
5
# do something periodically
6
end
7
end
Copied!
Configuration Example:
1
interval 0.5 # 0.5 seconds
2
interval 1s # 1 second
3
interval 1m # 1 minute = 60 seconds
4
interval 1h # 1 hour = 3600 seconds
5
interval 1d # 1 day = 86400 seconds
Copied!
Configuration Example:
1
interval 10m
Copied!

:bool

Defines a Boolean parameter.
Code Example:
1
config_param :deep_copy, :bool, default: false
2
3
def copy(object)
4
if @deep_copy
5
# deep copy
6
else
7
# shallow copy
8
end
9
end
Copied!
Configuration Example:
1
deep_copy true
Copied!

:enum

Defines an enumerated parameter.
Users can choose a value from the list. If a non-listed value is chosen, an error occurs on startup.
    Available options
      list: List of available values.
Code Example:
1
config_param :protocol_type, :enum, list: [:udp, :tcp], default: :udp
2
3
def send
4
case @protocol_type
5
when :udp
6
send_udp
7
when :tcp
8
send_tcp
9
end
10
end
Copied!
Configuration Example:
1
protocol_type tcp
Copied!

:array

Defines an array parameter.
Users can set an array value for a parameter.
    Available options
      value_type: Defines the type of the value.
      Available types: { :string, :integer, :float, :size, :bool, :time }
Code Example:
1
config_param :users, :array, default: [], value_type: :string
2
3
def available_user?(user)
4
@users.include?(user)
5
end
Copied!
Configuration Example:
1
users user1, user2, user3
2
users ["user1", "user2", "user3"] # written in JSON
Copied!
This configuration will be converted to:
1
["user1", "user2", "user3"]
Copied!

:hash

Defines a hash parameter.
    Available options
      symbolize_keys: If true, the keys are symbolized.
      value_type: Defines the same type for all values.
Code Example:
1
config_param :key_values, :hash, default: {}, symbolize_keys: true, value_type: :string
2
3
def do_something
4
value1 = @key_values[:key1]
5
value2 = @key_values[:key2]
6
# ...
7
end
Copied!
Configuration Example:
1
key_values {"key1": "value1", "key2": "value2"} # written in JSON
2
key_values key1:value1,key2:value2
Copied!
This configurations will be converted to:
1
{ key1: "value1", key2: "value2" }
Copied!
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last modified 4mo ago