fluent-plugin-couch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Yudai Odagiri <ixixizko _at_ gmail.com>
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = CouchDB output plugin for Fluent
2
+
3
+ == Component
4
+
5
+ === CouchDBOutput
6
+
7
+ Store fluent-event as CouchDB Document to CouchDB database.
8
+
9
+ == Configuratin
10
+
11
+ === CouchOutput
12
+
13
+ <match couch.**>
14
+ type couch
15
+ database fluent
16
+
17
+ # following attibutes are optional
18
+ host fluenter
19
+ port 10000
20
+
21
+ # Other buffer configurations here
22
+ </match>
23
+
24
+ == TODO
25
+ - Bulk Insert
26
+
27
+ === More configuration
28
+
29
+
30
+ == Tool
31
+
32
+ == Copyright
33
+
34
+ Copyright:: Copyright (c) 2011- Yudai Odagiri
35
+ License:: Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "fluent-plugin-couch"
9
+ gemspec.summary = "CouchDB output plugin for Fluent event collector"
10
+ gemspec.author = "Yudai Odagiri"
11
+ gemspec.email = "ixixizko@gmail.com"
12
+ gemspec.homepage = "http://github.com/fluent"
13
+ gemspec.has_rdoc = false
14
+ gemspec.require_paths = ["lib"]
15
+ gemspec.add_dependency "fluent", "~> 0.9.14"
16
+ gemspec.test_files = Dir["test/**/*.rb"]
17
+ gemspec.files = Dir["lib/**/*", "test/**/*.rb"] + %w[VERSION AUTHORS Rakefile]
18
+ gemspec.executables = []
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ Rake::TestTask.new(:test) do |t|
26
+ t.test_files = Dir['test/*_test.rb']
27
+ t.ruby_opts = ['-rubygems'] if defined? Gem
28
+ t.ruby_opts << '-I.'
29
+ end
30
+
31
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,86 @@
1
+ module Couch
2
+ require 'net/http'
3
+ class Server
4
+ def initialize(host, port, options = nil)
5
+ @host = host
6
+ @port = port
7
+ @options = options
8
+ end
9
+
10
+ def delete(uri)
11
+ request(Net::HTTP::Delete.new(uri))
12
+ end
13
+
14
+ def get(uri)
15
+ request(Net::HTTP::Get.new(uri))
16
+ end
17
+
18
+ def put(uri, json)
19
+ req = Net::HTTP::Put.new(uri)
20
+ req["content-type"] = "application/json"
21
+ req.body = json
22
+ request(req)
23
+ end
24
+
25
+ def post(uri, json)
26
+ req = Net::HTTP::Post.new(uri)
27
+ req["content-type"] = "application/json"
28
+ req.body = json
29
+ request(req)
30
+ end
31
+
32
+ def request(req)
33
+ res = Net::HTTP.start(@host, @port) { |http|http.request(req) }
34
+ res
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+ module Fluent
41
+ class CouchOutput < BufferedOutput
42
+ Fluent::Plugin.register_output('couch', self)
43
+
44
+ def initialize
45
+ super
46
+ require 'msgpack'
47
+ end
48
+
49
+ def configure(conf)
50
+ super
51
+ @database_name = '/'+conf['database'] if conf.has_key?('database')
52
+ raise ConfigError, "'database' parameter is required on couch output" if @database_name.nil?
53
+ @host = conf['host'] || 'localhost'
54
+ @port = conf['port'] || '5984'
55
+ end
56
+
57
+ def start
58
+ super
59
+ @couch = Couch::Server.new(@host, @port)
60
+ @couch.put(@database_name, "")
61
+ end
62
+
63
+ def shutdown
64
+ super
65
+ end
66
+
67
+ def format(tag, event)
68
+ event.record.to_msgpack
69
+ end
70
+
71
+ def write(chunk)
72
+ records = []
73
+ chunk.open { |io|
74
+ begin
75
+ MessagePack::Unpacker.new(io).each { |record| records << record }
76
+ rescue EOFError
77
+ # EOFError always occured when reached end of chunk.
78
+ end
79
+ }
80
+ #TODO: bulk insert
81
+ for record in records
82
+ @couch.post(@database_name,record.to_json)
83
+ end
84
+ end
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-couch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yudai Odagiri
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluent
16
+ requirement: &70215615176380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.14
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70215615176380
25
+ description:
26
+ email: ixixizko@gmail.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - AUTHORS
33
+ - Rakefile
34
+ - VERSION
35
+ - lib/fluent/plugin/out_couch.rb
36
+ - README.rdoc
37
+ homepage: http://github.com/fluent
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.7
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: CouchDB output plugin for Fluent event collector
61
+ test_files: []