fluent-plugin-mongo 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +85 -71
- data/VERSION +1 -1
- data/lib/fluent/plugin/in_mongo_tail.rb +17 -6
- data/lib/fluent/plugin/mongo_util.rb +27 -0
- data/lib/fluent/plugin/out_mongo.rb +14 -5
- metadata +15 -14
data/README.rdoc
CHANGED
@@ -1,33 +1,26 @@
|
|
1
|
-
= MongoDB plugin for
|
1
|
+
= MongoDB plugin for Fluentd
|
2
2
|
|
3
|
-
|
3
|
+
fluent-plugin-mongo provides input and output plugins for {Fluentd}[http://fluentd.org/].
|
4
4
|
|
5
|
-
|
5
|
+
= Installation
|
6
6
|
|
7
|
-
|
7
|
+
== Gems
|
8
8
|
|
9
|
-
|
10
|
-
You set _false_ to _include_time_key_ parameter if you disable this behaivor.
|
9
|
+
The gem is hosted at {Rubygems.org}[http://rubygems.org]. You can install the gem as follows:
|
11
10
|
|
12
|
-
|
11
|
+
$ fluent-gem install fluent-plugin-mongo
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
=== MongoReplSetOutput
|
17
|
-
|
18
|
-
Replica Set version of MongoOutput
|
13
|
+
= Plugins
|
19
14
|
|
20
|
-
|
15
|
+
== Output plugin
|
21
16
|
|
22
|
-
|
17
|
+
=== mongo
|
23
18
|
|
24
|
-
|
19
|
+
Store Fluentd event to MongoDB database.
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
== Configuration
|
21
|
+
==== Configuration
|
29
22
|
|
30
|
-
|
23
|
+
Use _mongo_ type in match.
|
31
24
|
|
32
25
|
<match mongo.**>
|
33
26
|
type mongo
|
@@ -42,12 +35,20 @@ Tail capped collection to input data.
|
|
42
35
|
capped
|
43
36
|
capped_size 100m
|
44
37
|
|
38
|
+
# Set 'user' and 'password' for authentication
|
39
|
+
user handa
|
40
|
+
password shinobu
|
41
|
+
|
45
42
|
# Other buffer configurations here
|
46
43
|
</match>
|
47
44
|
|
48
|
-
|
45
|
+
=== mongo(tag mapped mode)
|
49
46
|
|
50
|
-
|
47
|
+
Tag mapped to MongoDB collection automatically.
|
48
|
+
|
49
|
+
==== Configuration
|
50
|
+
|
51
|
+
Use _tag_mapped_ parameter in match of _mongo_ type.
|
51
52
|
|
52
53
|
If tag name is "foo.bar", auto create collection "foo.bar" and insert data.
|
53
54
|
|
@@ -68,48 +69,11 @@ If tag name is "foo.bar", auto create collection "foo.bar" and insert data.
|
|
68
69
|
# Other configurations here
|
69
70
|
</match>
|
70
71
|
|
71
|
-
|
72
|
+
=== mongo_replset
|
72
73
|
|
73
|
-
|
74
|
+
Replica Set version of mongo.
|
74
75
|
|
75
|
-
|
76
|
-
In such case, Mongo plugin marshals an invalid record using Marshal.dump
|
77
|
-
and re-inserts its to same collection.
|
78
|
-
|
79
|
-
If passed following invalid record:
|
80
|
-
|
81
|
-
{"key1": "invalid value", "key2": "valid value", "time": ISODate("2012-01-15T21:09:53Z") }
|
82
|
-
|
83
|
-
then Mongo plugin converts this record to following format:
|
84
|
-
|
85
|
-
{"__broken_data": Marshal.dump result of {"key1": "invalid value", "key2": "valid value"}, "time": ISODate("2012-01-15T21:09:53Z") }
|
86
|
-
|
87
|
-
Mongo-Ruby-Driver cannot detect an invalid attribute,
|
88
|
-
so Mongo plugin marshals all attributes excluding Fluentd keys("tag_key" and "time_key").
|
89
|
-
|
90
|
-
If you want to ignore an invalid record, set _true_ to _ignore_invalid_record_ parameter in match.
|
91
|
-
|
92
|
-
<match forward.*>
|
93
|
-
...
|
94
|
-
|
95
|
-
# ignore invalid documents at write operation
|
96
|
-
ignore_invalid_document true
|
97
|
-
|
98
|
-
...
|
99
|
-
</match>
|
100
|
-
|
101
|
-
===== Buffer size limitation
|
102
|
-
|
103
|
-
Mongo plugin has the limitation of buffer size.
|
104
|
-
Because MongoDB and mongo-ruby-driver checks the total object size at each insertion.
|
105
|
-
If total object size gets over the size limitation, then
|
106
|
-
MongoDB returns error or mongo-ruby-driver raises an exception.
|
107
|
-
|
108
|
-
So, Mongo plugin resets _buffer_chunk_limit_ if configurated value is larger than above limitation:
|
109
|
-
- Before v1.8, max of _buffer_chunk_limit_ is 2MB
|
110
|
-
- After v1.8, max of _buffer_chunk_limit_ is 10MB
|
111
|
-
|
112
|
-
=== MongoReplSetOutput
|
76
|
+
==== Configuration
|
113
77
|
|
114
78
|
Use _mongo_replset_ type in match.
|
115
79
|
|
@@ -133,7 +97,11 @@ Use _mongo_replset_ type in match.
|
|
133
97
|
#refresh_interval 60
|
134
98
|
</match>
|
135
99
|
|
136
|
-
===
|
100
|
+
=== mongo_backup
|
101
|
+
|
102
|
+
Store Fluentd event to local capped collection for backup.
|
103
|
+
|
104
|
+
==== Configuration
|
137
105
|
|
138
106
|
Use _mongo_backup_ type in match. _mongo_backup_ alwalys use capped collection.
|
139
107
|
|
@@ -148,7 +116,13 @@ Use _mongo_backup_ type in match. _mongo_backup_ alwalys use capped collection.
|
|
148
116
|
</store>
|
149
117
|
</match>
|
150
118
|
|
151
|
-
|
119
|
+
== Input plugin
|
120
|
+
|
121
|
+
=== mongo_tail
|
122
|
+
|
123
|
+
Tail capped collection to input data.
|
124
|
+
|
125
|
+
==== Configuration
|
152
126
|
|
153
127
|
Use _mongo_tail_ type in source.
|
154
128
|
|
@@ -166,21 +140,61 @@ Use _mongo_tail_ type in source.
|
|
166
140
|
id_store_file /Users/repeatedly/devel/fluent-plugin-mongo/last_id
|
167
141
|
</source>
|
168
142
|
|
169
|
-
|
143
|
+
= NOTE
|
170
144
|
|
171
|
-
|
145
|
+
== Broken data as a BSON
|
172
146
|
|
173
|
-
|
174
|
-
|
175
|
-
-
|
147
|
+
Fluentd event sometimes has an invalid record as a BSON.
|
148
|
+
In such case, Mongo plugin marshals an invalid record using Marshal.dump
|
149
|
+
and re-inserts its to same collection.
|
150
|
+
|
151
|
+
If passed following invalid record:
|
152
|
+
|
153
|
+
{"key1": "invalid value", "key2": "valid value", "time": ISODate("2012-01-15T21:09:53Z") }
|
154
|
+
|
155
|
+
then Mongo plugin converts this record to following format:
|
156
|
+
|
157
|
+
{"__broken_data": Marshal.dump result of {"key1": "invalid value", "key2": "valid value"}, "time": ISODate("2012-01-15T21:09:53Z") }
|
158
|
+
|
159
|
+
Mongo-Ruby-Driver cannot detect an invalid attribute,
|
160
|
+
so Mongo plugin marshals all attributes excluding Fluentd keys("tag_key" and "time_key").
|
161
|
+
|
162
|
+
If you want to ignore an invalid record, set _true_ to _ignore_invalid_record_ parameter in match.
|
176
163
|
|
177
|
-
|
164
|
+
<match forward.*>
|
165
|
+
...
|
166
|
+
|
167
|
+
# ignore invalid documents at write operation
|
168
|
+
ignore_invalid_record true
|
169
|
+
|
170
|
+
...
|
171
|
+
</match>
|
172
|
+
|
173
|
+
== Buffer size limitation
|
174
|
+
|
175
|
+
Mongo plugin has the limitation of buffer size.
|
176
|
+
Because MongoDB and mongo-ruby-driver checks the total object size at each insertion.
|
177
|
+
If total object size gets over the size limitation, then
|
178
|
+
MongoDB returns error or mongo-ruby-driver raises an exception.
|
179
|
+
|
180
|
+
So, Mongo plugin resets _buffer_chunk_limit_ if configurated value is larger than above limitation:
|
181
|
+
- Before v1.8, max of _buffer_chunk_limit_ is 2MB
|
182
|
+
- After v1.8, max of _buffer_chunk_limit_ is 10MB
|
183
|
+
|
184
|
+
= Tool
|
178
185
|
|
179
186
|
You can tail mongo capped collection.
|
180
187
|
|
181
|
-
mongo-tail -f
|
188
|
+
$ mongo-tail -f
|
189
|
+
|
190
|
+
= TODO
|
191
|
+
|
192
|
+
== More configuration
|
193
|
+
|
194
|
+
- Multi process
|
195
|
+
- etc
|
182
196
|
|
183
|
-
|
197
|
+
= Copyright
|
184
198
|
|
185
199
|
Copyright:: Copyright (c) 2011- Masahiro Nakagawa
|
186
200
|
License:: Apache License, Version 2.0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
@@ -4,6 +4,9 @@ module Fluent
|
|
4
4
|
class MongoTailInput < Input
|
5
5
|
Plugin.register_input('mongo_tail', self)
|
6
6
|
|
7
|
+
require 'fluent/plugin/mongo_util'
|
8
|
+
include MongoUtil
|
9
|
+
|
7
10
|
config_param :database, :string
|
8
11
|
config_param :collection, :string
|
9
12
|
config_param :host, :string, :default => 'localhost'
|
@@ -18,9 +21,9 @@ class MongoTailInput < Input
|
|
18
21
|
config_param :id_store_file, :string, :default => nil
|
19
22
|
|
20
23
|
def initialize
|
24
|
+
super
|
21
25
|
require 'mongo'
|
22
26
|
require 'bson'
|
23
|
-
super
|
24
27
|
end
|
25
28
|
|
26
29
|
def configure(conf)
|
@@ -62,11 +65,19 @@ class MongoTailInput < Input
|
|
62
65
|
private
|
63
66
|
|
64
67
|
def get_capped_collection
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
begin
|
69
|
+
db = authenticate(Mongo::Connection.new(@host, @port).db(@database))
|
70
|
+
raise ConfigError, "'#{@database}.#{@collection}' not found: node = #{@host}:#{@port}" unless db.collection_names.include?(@collection)
|
71
|
+
collection = db.collection(@collection)
|
72
|
+
raise ConfigError, "'#{@database}.#{@collection}' is not capped: node = #{@host}:#{@port}" unless collection.capped?
|
73
|
+
collection
|
74
|
+
rescue Mongo::ConnectionFailure => e
|
75
|
+
$log.fatal "Failed to connect to 'mongod'. Please restart 'fluentd' after 'mongod' started: #{e}"
|
76
|
+
exit!
|
77
|
+
rescue Mongo::OperationFailure => e
|
78
|
+
$log.fatal "Operation failed. Probably, 'mongod' needs an authentication: #{e}"
|
79
|
+
exit!
|
80
|
+
end
|
70
81
|
end
|
71
82
|
|
72
83
|
def tailoop(cursor)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fluent
|
2
|
+
|
3
|
+
|
4
|
+
module MongoUtil
|
5
|
+
def self.included(klass)
|
6
|
+
klass.instance_eval {
|
7
|
+
config_param :user, :string, :default => nil
|
8
|
+
config_param :password, :string, :default => nil
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def authenticate(db)
|
13
|
+
unless @user.nil? || @password.nil?
|
14
|
+
begin
|
15
|
+
db.authenticate(@user, @password)
|
16
|
+
rescue Mongo::AuthenticationError => e
|
17
|
+
$log.fatal e
|
18
|
+
exit!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
db
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
@@ -4,6 +4,9 @@ module Fluent
|
|
4
4
|
class MongoOutput < BufferedOutput
|
5
5
|
Fluent::Plugin.register_output('mongo', self)
|
6
6
|
|
7
|
+
require 'fluent/plugin/mongo_util'
|
8
|
+
include MongoUtil
|
9
|
+
|
7
10
|
include SetTagKeyMixin
|
8
11
|
config_set_default :include_tag_key, false
|
9
12
|
|
@@ -26,8 +29,8 @@ class MongoOutput < BufferedOutput
|
|
26
29
|
def initialize
|
27
30
|
super
|
28
31
|
require 'mongo'
|
29
|
-
require 'fluent/plugin/mongo_ext'
|
30
32
|
require 'msgpack'
|
33
|
+
require 'fluent/plugin/mongo_ext'
|
31
34
|
|
32
35
|
@clients = {}
|
33
36
|
@connection_options = {}
|
@@ -168,7 +171,8 @@ class MongoOutput < BufferedOutput
|
|
168
171
|
end
|
169
172
|
|
170
173
|
def get_connection
|
171
|
-
Mongo::Connection.new(@host, @port, @connection_options).db(@database)
|
174
|
+
db = Mongo::Connection.new(@host, @port, @connection_options).db(@database)
|
175
|
+
authenticate(db)
|
172
176
|
end
|
173
177
|
|
174
178
|
# Following limits are heuristic. BSON is sometimes bigger than MessagePack and JSON.
|
@@ -179,9 +183,13 @@ class MongoOutput < BufferedOutput
|
|
179
183
|
begin
|
180
184
|
limit = mongod_version >= "1.8.0" ? LIMIT_AFTER_v1_8 : LIMIT_BEFORE_v1_8 # TODO: each version comparison
|
181
185
|
rescue Mongo::ConnectionFailure => e
|
182
|
-
$log.
|
183
|
-
|
186
|
+
$log.fatal "Failed to connect to 'mongod'. Please restart 'fluentd' after 'mongod' started: #{e}"
|
187
|
+
exit!
|
188
|
+
rescue Mongo::OperationFailure => e
|
189
|
+
$log.fatal "Operation failed. Probably, 'mongod' needs an authentication: #{e}"
|
190
|
+
exit!
|
184
191
|
rescue Exception => e
|
192
|
+
# TODO: should do exit?
|
185
193
|
$log.warn "mongo unknown error #{e}, set #{LIMIT_BEFORE_v1_8} to chunk limit"
|
186
194
|
limit = LIMIT_BEFORE_v1_8
|
187
195
|
end
|
@@ -195,7 +203,8 @@ class MongoOutput < BufferedOutput
|
|
195
203
|
end
|
196
204
|
|
197
205
|
def mongod_version
|
198
|
-
Mongo::Connection.new(@host, @port).db('admin')
|
206
|
+
db = authenticate(Mongo::Connection.new(@host, @port).db('admin'))
|
207
|
+
db.command('serverStatus' => 1)['version']
|
199
208
|
end
|
200
209
|
end
|
201
210
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152356120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.10.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152356120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongo
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152354440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: 1.5.2
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *2152354440
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: rake
|
41
|
-
requirement: &
|
41
|
+
requirement: &2152352640 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ! '>='
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: 0.9.2
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *2152352640
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: simplecov
|
52
|
-
requirement: &
|
52
|
+
requirement: &2152351520 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ! '>='
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: 0.5.4
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *2152351520
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rr
|
63
|
-
requirement: &
|
63
|
+
requirement: &2152350480 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ! '>='
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
version: 1.0.0
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *2152350480
|
72
72
|
description: MongoDB plugin for Fluent event collector
|
73
73
|
email: repeatedly@gmail.com
|
74
74
|
executables:
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- fluent-plugin-mongo.gemspec
|
89
89
|
- lib/fluent/plugin/in_mongo_tail.rb
|
90
90
|
- lib/fluent/plugin/mongo_ext.rb
|
91
|
+
- lib/fluent/plugin/mongo_util.rb
|
91
92
|
- lib/fluent/plugin/out_mongo.rb
|
92
93
|
- lib/fluent/plugin/out_mongo_backup.rb
|
93
94
|
- lib/fluent/plugin/out_mongo_replset.rb
|
@@ -110,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
111
|
version: '0'
|
111
112
|
segments:
|
112
113
|
- 0
|
113
|
-
hash:
|
114
|
+
hash: 688925002882805851
|
114
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
116
|
none: false
|
116
117
|
requirements:
|
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
120
|
version: '0'
|
120
121
|
segments:
|
121
122
|
- 0
|
122
|
-
hash:
|
123
|
+
hash: 688925002882805851
|
123
124
|
requirements: []
|
124
125
|
rubyforge_project:
|
125
126
|
rubygems_version: 1.8.10
|