Fluentd
Search…
Plugin Helper: Parser
The parser plugin helper manages the lifecycle of the parser plugin.
Here is an example:
1
require 'fluent/plugin/input'
2
3
module Fluent::Plugin
4
class ExampleInput < Input
5
Fluent::Plugin.register_input('example', self)
6
7
# 1. Load parser helper
8
helpers :parser
9
10
# Omit `shutdown` and other plugin APIs
11
12
def configure(conf)
13
super
14
15
# 2. Create parser plugin instance
16
@parser = parser_create
17
end
18
19
def start
20
super
21
22
# Use parser helper in combination usually with other plugin helpers
23
timer_execute(:example_timer, 10) do
24
read_raw_data do |text|
25
# 3. Call `@parser.parse(text)` to parse raw data
26
@parser.parse(text) do |time, record|
27
router.emit(tag, time, record)
28
end
29
end
30
end
31
end
32
end
33
end
Copied!
For more details, see the following articles:

Methods

parser_create(usage: "", type: nil, conf: nil, default_type: nil)

This method creates a parser plugin instance with the given parameters.
    usage: unique name required for multiple parsers
    type: parser type
    conf: parser plugin configuration
    default_type: default parser type
Examples
1
# Create parser plugin instance using <parse> section in fluent.conf during configure phase
2
@parser = parser_create
3
@parser.parse(text) do |time, record|
4
# ...
5
end
6
7
# Create JSON parser
8
@json_parser = parser_create(usage: 'parser_in_example_json', type: 'json')
9
@json_parser.parse(json) do |time, record|
10
# ...
11
end
12
13
# Create MessagePack parser
14
@msgpack_parser = parser_create(usage: 'parser_in_example_msgpack', type: 'msgpack')
15
@msgpack_parser.parse(msgpack_binary) do |time, record|
16
# ...
17
end
Copied!

Plugins using parser

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