fluent-plugin-mongo 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,7 +1,15 @@
1
1
  = MongoDB output plugin for Fluent
2
2
 
3
+ == Component
4
+
5
+ === MongoOutput
6
+
7
+ Output to MongoDB database.
8
+
3
9
  == Configuratin
4
10
 
11
+ === MongoOutput
12
+
5
13
  <match mongo.**>
6
14
  type mongo
7
15
  database fluent
@@ -14,6 +22,21 @@
14
22
  # Other buffer configurations here
15
23
  </match>
16
24
 
25
+ === Backup to local capped collection
26
+
27
+ Use <store> section.
28
+
29
+ <match mongo.**>
30
+ type mongo
31
+ database fluent
32
+ collection test
33
+
34
+ <store>
35
+ size 100000
36
+ max 1000
37
+ </store>
38
+ </match>
39
+
17
40
  == TODO
18
41
 
19
42
  === More configuration
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gemspec.has_rdoc = false
14
14
  gemspec.require_paths = ["lib"]
15
15
  gemspec.add_dependency "fluent", "~> 0.9.14"
16
- gemspec.add_dependency "mongo", "~> 1.2.0"
16
+ gemspec.add_dependency "mongo", ">= 1.2.0"
17
17
  gemspec.test_files = Dir["test/**/*.rb"]
18
18
  gemspec.files = Dir["bin/**/*", "lib/**/*", "test/**/*.rb"] + %w[VERSION AUTHORS Rakefile]
19
19
  gemspec.executables = []
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -13,21 +13,36 @@ class MongoOutput < BufferedOutput
13
13
  def configure(conf)
14
14
  super
15
15
 
16
- raise ConfigError, "'database' parameter is required on file output" unless @database = conf['database']
17
- raise ConfigError, "'collection' parameter is required on file output" unless @collection = conf['collection']
16
+ raise ConfigError, "'database' parameter is required on Mongo output" unless @database_name = conf['database']
17
+ raise ConfigError, "'collection' parameter is required on Mongo output" unless @collection_name = conf['collection']
18
+ @host, @port = host_and_port(conf)
18
19
 
19
- @host = conf.has_key?('host') ? conf['host'] : 'localhost'
20
- @port = conf.has_key?('port') ? conf['port'] : 27017
20
+ # capped configuration
21
+ if capped_conf = conf.elements.first
22
+ raise ConfigError, "'size' parameter is required on <store> of Mongo output" unless capped_conf.has_key?('size')
23
+ @capped_argument = {:capped => true}
24
+ @capped_argument[:size] = Integer(capped_conf['size'])
25
+ @capped_argument[:max] = Integer(capped_conf['max']) if capped_conf.has_key?('max')
26
+
27
+ @capped_database_name = capped_conf['database'] || 'fluent'
28
+ @capped_collection_name = capped_conf['collection'] || '__backup'
29
+ @capped_host, @capped_port = host_and_port(capped_conf)
30
+ end
31
+
32
+ @backuped = false
21
33
  end
22
34
 
23
35
  def start
24
36
  super
25
- @collection = Mongo::Connection.new(@host, @port).db(@database).collection(@collection)
37
+ @collection = Mongo::Connection.new(@host, @port).db(@database_name).collection(@collection_name)
38
+ @capped = capped_collection unless @capped_argument.nil?
26
39
  end
27
40
 
28
41
  def shutdown
29
42
  # Mongo::Connection checks alive or closed myself
30
43
  @collection.db.connection.close
44
+ @capped.db.connection.close unless @capped.nil?
45
+ super
31
46
  end
32
47
 
33
48
  def format(tag, event)
@@ -43,7 +58,32 @@ class MongoOutput < BufferedOutput
43
58
  # EOFError always occured when reached end of chunk.
44
59
  end
45
60
  }
61
+
62
+ unless @backuped or @capped.nil?
63
+ @capped.insert(records)
64
+ @backuped = true
65
+ end
66
+
46
67
  @collection.insert(records)
68
+ @backuped = false
69
+ end
70
+
71
+ private
72
+
73
+ def host_and_port(conf)
74
+ host = conf['host'] || 'localhost'
75
+ port = conf['port'] || 27017
76
+ [host, Integer(port)]
77
+ end
78
+
79
+ def capped_collection
80
+ db = Mongo::Connection.new(@capped_host, @capped_port).db(@capped_database_name)
81
+ if db.collection_names.include?(@capped_collection_name)
82
+ # TODO: Verify capped configuraton
83
+ db.collection(@capped_collection_name)
84
+ else
85
+ db.create_collection(@capped_collection_name, @capped_argument)
86
+ end
47
87
  end
48
88
  end
49
89
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Masahiro Nakagawa
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-28 00:00:00 +09:00
17
+ date: 2011-10-02 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  segments:
44
44
  - 1