Class: Fluent::RackspaceCloudFilesOutput
- Inherits:
-
TimeSlicedOutput
- Object
- TimeSlicedOutput
- Fluent::RackspaceCloudFilesOutput
- Includes:
- Mixin::ConfigPlaceholders, SetTagKeyMixin, SetTimeKeyMixin
- Defined in:
- lib/fluent/plugin/out_rackspace_cloud_files.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ RackspaceCloudFilesOutput
constructor
A new instance of RackspaceCloudFilesOutput.
- #placeholders ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ RackspaceCloudFilesOutput
Returns a new instance of RackspaceCloudFilesOutput.
8 9 10 11 12 13 14 15 |
# File 'lib/fluent/plugin/out_rackspace_cloud_files.rb', line 8 def initialize super require 'fog' require 'zlib' require 'time' require 'tempfile' require 'open3' end |
Instance Method Details
#configure(conf) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fluent/plugin/out_rackspace_cloud_files.rb', line 47 def configure(conf) super if format_json = conf['format_json'] @format_json = true else @format_json = false end @ext, @mime_type = case @store_as when 'gzip' then ['gz', 'application/x-gzip'] when 'json' then ['json', 'application/json'] else ['txt', 'text/plain'] end @timef = TimeFormatter.new(@time_format, @localtime) if @localtime @path_slicer = Proc.new {|path| Time.now.strftime(path) } else @path_slicer = Proc.new {|path| Time.now.utc.strftime(path) } end end |
#format(tag, time, record) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fluent/plugin/out_rackspace_cloud_files.rb', line 89 def format(tag, time, record) if @include_time_key || !@format_json time_str = @timef.format(time) end # copied from each mixin because current TimeSlicedOutput can't support mixins. if @include_tag_key record[@tag_key] = tag end if @include_time_key record[@time_key] = time_str end if @format_json Yajl.dump(record) + "\n" else "#{time_str}\t#{tag}\t#{Yajl.dump(record)}\n" end end |
#placeholders ⇒ Object
43 44 45 |
# File 'lib/fluent/plugin/out_rackspace_cloud_files.rb', line 43 def placeholders [:percent] end |
#start ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fluent/plugin/out_rackspace_cloud_files.rb', line 75 def start super Excon.defaults[:ssl_verify_peer] = @ssl_verify @storage = Fog::Storage.new :provider => 'Rackspace', :rackspace_auth_url => @rackspace_auth_url, :rackspace_username => @rackspace_username, :rackspace_api_key => @rackspace_api_key, :rackspace_region => @rackspace_region check_container end |
#write(chunk) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/fluent/plugin/out_rackspace_cloud_files.rb', line 109 def write(chunk) i = 0 begin path = @path_slicer.call(@path) values_for_swift_object_key = { "path" => path, "time_slice" => chunk.key, "file_extension" => @ext, "index" => i } swift_path = @object_key_format.gsub(%r(%{[^}]+})) { |expr| values_for_swift_object_key[expr[2...expr.size-1]] } i += 1 end while check_object_exists(@rackspace_container, swift_path) tmp = Tempfile.new("rackspace-cloud-files-") begin if @store_as == "gzip" w = Zlib::GzipWriter.new(tmp) chunk.write_to(w) w.close else chunk.write_to(tmp) tmp.close end File.open(tmp.path) do |file| @storage.put_object(@rackspace_container, swift_path, file, {:content_type => @mime_type}) end $log.info "Put Log to Rackspace Cloud Files. container=#{@rackspace_container} object=#{swift_path}" ensure tmp.close(true) rescue nil w.close rescue nil w.unlink rescue nil end end |