class Fluent::GStoreOutput
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gstore.rb, line 7 def initialize super require 'gstore' require 'kconv' require 'zlib' require 'time' require 'tempfile' require "pathname" require "rexml/document" end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gstore.rb, line 25 def configure(conf) super @timef = TimeFormatter.new(@time_format, @localtime) end
exists?(source)
click to toggle source
# File lib/fluent/plugin/out_gstore.rb, line 44 def exists?(source) begin REXML::Document.new source # :TODO false rescue REXML::ParseException => e true rescue Exception => e true end end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_gstore.rb, line 39 def format(tag, time, record) time_str = @timef.format(time) "#{time_str}\t#{tag}\t#{record.to_json}\n" end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_gstore.rb, line 30 def start super options = { :access_key => @gstore_key_id, :secret_key => @gstore_sec_key } @gstore = GStore::Client.new(options) end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_gstore.rb, line 56 def write(chunk) i = 0 begin gstorepath = "#{@path}#{chunk.key}_#{i}.gz" i += 1 end while exists? @gstore.get_object(@gstore_bucket, gstorepath) tmp = Tempfile.new("gstore-") w = Zlib::GzipWriter.new(tmp) begin chunk.write_to(w) w.close @gstore.put_object( @gstore_bucket, gstorepath, :data => Pathname.new(tmp.path).read()) ensure w.close rescue nil end end