Class: Fluent::MongoOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::MongoOutput
show all
- Includes:
- MongoUtil, SetTagKeyMixin, SetTimeKeyMixin
- Defined in:
- lib/fluent/plugin/out_mongo.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from MongoUtil
#authenticate, included
Constructor Details
Returns a new instance of MongoOutput.
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/fluent/plugin/out_mongo.rb', line 29
def initialize
super
require 'mongo'
require 'msgpack'
require 'fluent/plugin/mongo_ext'
@clients = {}
@connection_options = {}
@collection_options = {:capped => false}
end
|
Instance Attribute Details
#collection_options ⇒ Object
Returns the value of attribute collection_options.
27
28
29
|
# File 'lib/fluent/plugin/out_mongo.rb', line 27
def collection_options
@collection_options
end
|
Class Method Details
MongoDB uses BSON’s Date for time.
67
68
69
|
# File 'lib/fluent/plugin/out_mongo.rb', line 67
def @timef.format_nocache(time)
time
end
|
Instance Method Details
40
41
42
43
44
45
46
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
|
# File 'lib/fluent/plugin/out_mongo.rb', line 40
def configure(conf)
super
@tag_mapped = true if conf.has_key?('tag_mapped')
raise ConfigError, "normal mode requires collection parameter" if !@tag_mapped and !conf.has_key?('collection')
if remove_tag_prefix = conf['remove_tag_prefix']
@remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
end
if conf.has_key?('capped')
raise ConfigError, "'capped_size' parameter is required on <store> of Mongo output" unless conf.has_key?('capped_size')
@collection_options[:capped] = true
@collection_options[:size] = Config.size_value(conf['capped_size'])
@collection_options[:max] = Config.size_value(conf['capped_max']) if conf.has_key?('capped_max')
end
if @buffer.respond_to?(:buffer_chunk_limit)
@buffer.buffer_chunk_limit = available_buffer_chunk_limit
else
$log.warn "#{Fluent::VERSION} does not have :buffer_chunk_limit. Be careful when insert large documents to MongoDB"
end
@connection_options[:safe] = @safe
def @timef.format_nocache(time)
time
end
$log.debug "Setup mongo configuration: mode = #{@tag_mapped ? 'tag mapped' : 'normal'}"
end
|
#emit(tag, es, chain) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/fluent/plugin/out_mongo.rb', line 88
def emit(tag, es, chain)
if @tag_mapped
super(tag, es, chain, tag)
else
super(tag, es, chain)
end
end
|
84
85
86
|
# File 'lib/fluent/plugin/out_mongo.rb', line 84
def format(tag, time, record)
[time, record].to_msgpack
end
|
#shutdown ⇒ Object
78
79
80
81
82
|
# File 'lib/fluent/plugin/out_mongo.rb', line 78
def shutdown
@clients.values.each { |client| client.db.connection.close }
super
end
|
#start ⇒ Object
74
75
76
|
# File 'lib/fluent/plugin/out_mongo.rb', line 74
def start
super
end
|
#write(chunk) ⇒ Object
97
98
99
100
101
|
# File 'lib/fluent/plugin/out_mongo.rb', line 97
def write(chunk)
collection_name = @tag_mapped ? chunk.key : @collection
operate(get_or_create_collection(collection_name), collect_records(chunk))
end
|