The storage
plugin helper manages the plugin's internal states.
Here is an example:
require 'fluent/plugin/input'​module Fluent::Pluginclass ExampleInput < InputFluent::Plugin.register_input('awesome_example', self)​# 1. Load storage helperhelpers :storage, :thread​DEFAULT_STORAGE_TYPE = 'local'​# Omit `shutdown` and other plugin APIs​def initializesuper​@storage = nilend​def configure(conf)super​# 2. Create storage with unique nameconfig = conf.elements(name: 'storage').first@storage = storage_create(usage: 'awesome_index', conf: config, default_type: DEFAULT_STORAGE_TYPE)end​def startsuper​# 3. Call storage plugin helpers get/put methods@storage.put(:awesome_index, 0) unless @storage.get(:awesome_index)thread_create(:awesome_input_runner, &method(:run))end​def runwhile thread_current_running?current_time = Time.now.to_ibreak unless (thread_current_running? && Time.now.to_i <= current_time)router.emit('awesome', Fluent::Engine.now, generate)sleep 0.1endend​def generate# 4. Update storage plugin helper's storing value@storage.update(:awesome_index) { |v| v + 1 }endendend
The created storage is managed by the plugin helper. No need of storage shutdown code in plugin's shutdown
. It shutdowns the created storages automatically.
For more details, see Storage section.
This method executes storage with the given parameters and routine.
usage
: unique string value (default: ''
)
type
: storage plugin type (default: nil
)
conf
: storage plugin configuration (default: nil
)
default_conf
: storage plugin default configuration (default: nil
)
Instance Type | Attributes |
Raw | persistent && persistent_always? || otherwise
| Persistent Wrapper | persistent
| Synchronized Wrapper | !synchronized?
|
Storage plugins will handle as-is.
This wrapper makes the handled storage plugin operate values persistently.
This wrapper makes handled storage plugin operate values synchronically.
Storage plugin helper encapsulates storage plugin implementation. Normally, the following methods will be called by the owner plugin through this plugin helper:
This method loads persistently stored value.
This method saves value persistently.
key
: symbol value.
This method obtains stored value by key.
key
: symbol value.
defval
: default value.
This method obtains the stored value by key. If missing, it returns the default value.
key
: symbol value.
value
: store value.
This method updates the stored value by key.
key
: symbol value.
This method deletes the stored value by key.
key
: symbol value.
&block
: a Proc
object.
This method updates the stored value using a Proc
object.
​in_sample
​
​in_windows_eventlog
​
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.