Class: Fluent::SndacsOutput
- Inherits:
-
TimeSlicedOutput
- Object
- TimeSlicedOutput
- Fluent::SndacsOutput
- Defined in:
- lib/fluent/plugin/out_sndacs.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ SndacsOutput
constructor
A new instance of SndacsOutput.
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ SndacsOutput
Returns a new instance of SndacsOutput.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fluent/plugin/out_sndacs.rb', line 5 def initialize super require 'tempfile' require 'zlib' #A quick fix for the encoding problem #see https://github.com/fluent/fluentd/issues/76 encoding = Encoding.default_internal Encoding.default_internal = nil require 'sndacs' Encoding.default_internal = encoding end |
Instance Method Details
#configure(conf) ⇒ Object
23 24 25 26 27 |
# File 'lib/fluent/plugin/out_sndacs.rb', line 23 def configure(conf) super @formatter = TimeFormatter.new(nil, @localtime) end |
#format(tag, time, record) ⇒ Object
36 37 38 |
# File 'lib/fluent/plugin/out_sndacs.rb', line 36 def format(tag, time, record) "#{@formatter.format(time)}\t#{tag}\t#{record.to_json}\n" end |
#start ⇒ Object
29 30 31 32 33 34 |
# File 'lib/fluent/plugin/out_sndacs.rb', line 29 def start super service = Sndacs::Service.new(:access_key_id => @access_key_id, :secret_access_key => @secret_access_key) @bucket_ = service.buckets.find(@bucket) end |
#write(chunk) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fluent/plugin/out_sndacs.rb', line 40 def write(chunk) i = 1 while true object = @bucket_.objects.build("#{@path}#{chunk.key}_#{i}.gz") break unless object.exists? i += 1 end file = Tempfile.new("sndacs-") Zlib::GzipWriter.open(file) do |writer| chunk.write_to(writer) end object.content = File.read(file) object.save end |