Plugin Helper: Storage
require 'fluent/plugin/input'
module Fluent::Plugin
class ExampleInput < Input
Fluent::Plugin.register_input('awesome_example', self)
# 1. Load storage helper
helpers :storage, :thread
DEFAULT_STORAGE_TYPE = 'local'
# Omit `shutdown` and other plugin APIs
def initialize
super
@storage = nil
end
def configure(conf)
super
# 2. Create storage with unique name
config = conf.elements(name: 'storage').first
@storage = storage_create(usage: 'awesome_index', conf: config, default_type: DEFAULT_STORAGE_TYPE)
end
def start
super
# 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 run
while thread_current_running?
current_time = Time.now.to_i
break unless (thread_current_running? && Time.now.to_i <= current_time)
router.emit('awesome', Fluent::Engine.now, generate)
sleep 0.1
end
end
def generate
# 4. Update storage plugin helper's storing value
@storage.update(:awesome_index) { |v| v + 1 }
end
end
endMethods
storage_create(usage: '', type: nil, conf: nil, default_type: nil)
storage_create(usage: '', type: nil, conf: nil, default_type: nil)Storage Plugin Helper Instance Types
Raw
Persistent Wrapper
Synchronized Wrapper
Common Methods
load
loadsave
saveget(key)
get(key)fetch(key, defval)
fetch(key, defval)put(key, value)
put(key, value)delete(key)
delete(key)update(key, &block)
update(key, &block)Plugins using storage
storageLast updated
Was this helpful?