Class: Fluent::Plugin::MemcachedOutput

Inherits:
Output
  • Object
show all
Includes:
SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_memcached.rb

Constant Summary collapse

DEFAULT_BUFFER_TYPE =
'memory'
DEFAULT_FORMAT_TYPE =
'csv'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



33
34
35
# File 'lib/fluent/plugin/out_memcached.rb', line 33

def formatter
  @formatter
end

#memcachedObject

Returns the value of attribute memcached.



32
33
34
# File 'lib/fluent/plugin/out_memcached.rb', line 32

def memcached
  @memcached
end

Instance Method Details

#configure(conf) ⇒ Object



35
36
37
38
39
40
# File 'lib/fluent/plugin/out_memcached.rb', line 35

def configure(conf)
  compat_parameters_convert(conf, :buffer, :inject, :formatter)
  super

  @formatter = formatter_create
end

#format(tag, time, record) ⇒ Object



54
55
56
57
58
59
# File 'lib/fluent/plugin/out_memcached.rb', line 54

def format(tag, time, record)
  record = inject_values_to_record(tag, time, record)

  key = @include_key ? record[@key] : record.delete(@key)
  [time, key, @formatter.format(tag, time, record).chomp].to_msgpack
end

#formatted_to_msgpack_binary?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/fluent/plugin/out_memcached.rb', line 61

def formatted_to_msgpack_binary?
  true
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fluent/plugin/out_memcached.rb', line 65

def multi_workers_ready?
  true
end

#shutdownObject



48
49
50
51
52
# File 'lib/fluent/plugin/out_memcached.rb', line 48

def shutdown
  @memcached.close

  super
end

#startObject



42
43
44
45
46
# File 'lib/fluent/plugin/out_memcached.rb', line 42

def start
  super

  @memcached = Dalli::Client.new("#{@host}:#{@port}")
end

#write(chunk) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/fluent/plugin/out_memcached.rb', line 69

def write(chunk)
  chunk.msgpack_each do |time, key, value|
    unless @increment
      @memcached.set(key, value)
      next
    end

    @memcached.incr(key, value.to_i, nil, value.to_i)
  end
end