fluent-plugin-sqlite3 0.0.0 → 0.1.0
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/lib/fluent/plugin/out_sqlite3.rb +84 -1
- metadata +36 -4
@@ -1,2 +1,85 @@
|
|
1
|
-
|
1
|
+
require "sqlite3"
|
2
|
+
|
3
|
+
class Fluent::Sqlite3Output < Fluent::BufferedOutput
|
4
|
+
Fluent::Plugin.register_output('sqlite3', self)
|
5
|
+
|
6
|
+
config_param :path, :string
|
7
|
+
config_param :table, :string, :default => nil
|
8
|
+
config_param :columns, :string, :default => nil
|
9
|
+
config_param :includes, :string, :default => nil
|
10
|
+
config_param :excludes, :string, :default => nil
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure(conf)
|
17
|
+
super
|
18
|
+
@type = conf["type"]
|
19
|
+
if (@table and not(@columns)) or (not(@table) and @columns)
|
20
|
+
raise "strict mode requires table and columns parameters"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
DELIMITER = / *, */
|
25
|
+
|
26
|
+
def start
|
27
|
+
super
|
28
|
+
@db = ::SQLite3::Database.new @path
|
29
|
+
@stmts = {}
|
30
|
+
if @table
|
31
|
+
cols = @columns.split(DELIMITER).map {|e| ":#{e}"}.join(",")
|
32
|
+
@stmts[@table] = @db.prepare "INSERT INTO #{@table}(#{@columns}) VALUES(#{cols})"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_insert(table, columns)
|
37
|
+
cols = columns.split(DELIMITER).map {|e| ":#{e}"}.join(",")
|
38
|
+
"INSERT INTO #{table}(#{columns}) VALUES(#{cols})"
|
39
|
+
end
|
40
|
+
|
41
|
+
def shutdown
|
42
|
+
super
|
43
|
+
$log.debug "shutdown"
|
44
|
+
@stmts.each {|k,v| v.close}
|
45
|
+
@db.close
|
46
|
+
end
|
47
|
+
|
48
|
+
def format(tag, time, record)
|
49
|
+
[tag, time, record].to_msgpack
|
50
|
+
end
|
51
|
+
|
52
|
+
def write(chunk)
|
53
|
+
@db.transaction
|
54
|
+
begin
|
55
|
+
write1(chunk)
|
56
|
+
@db.commit
|
57
|
+
rescue => ex
|
58
|
+
@db.rollback
|
59
|
+
$log.error "rollback: ", ex
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def write1(chunk)
|
64
|
+
chunk.msgpack_each do |tag, time, record|
|
65
|
+
if record.keys.length == 0
|
66
|
+
$log.warn "no any keys for #{tag}"
|
67
|
+
return
|
68
|
+
end
|
69
|
+
table = (@table or tag.slice(@type.length + 1, tag.length))
|
70
|
+
if @includes
|
71
|
+
(record.keys - @includes.split(DELIMITER)).each {|e| record.delete e}
|
72
|
+
end
|
73
|
+
if @excludes
|
74
|
+
@excludes.split(DELIMITER).each {|e| record.delete e}
|
75
|
+
end
|
76
|
+
unless @stmts[table]
|
77
|
+
cols = record.keys.join ","
|
78
|
+
@db.execute "CREATE TABLE IF NOT EXISTS #{table} (id INTEGER PRIMARY KEY AUTOINCREMENT,#{cols})"
|
79
|
+
@stmts[table] = @db.prepare (a = to_insert(table, cols))
|
80
|
+
$log.debug "create a new table, #{table.upcase} (it may have been already created)"
|
81
|
+
end
|
82
|
+
@stmts[table].execute record
|
83
|
+
end
|
84
|
+
end
|
2
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sqlite3
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
14
46
|
description: fluentd output to sqlite3
|
15
47
|
email: ktmtmks@gmail.com
|
16
48
|
executables: []
|
@@ -18,7 +50,7 @@ extensions: []
|
|
18
50
|
extra_rdoc_files: []
|
19
51
|
files:
|
20
52
|
- lib/fluent/plugin/out_sqlite3.rb
|
21
|
-
homepage:
|
53
|
+
homepage: https://github.com/tmtk75/fluent-plugin-sqlite3.git
|
22
54
|
licenses: []
|
23
55
|
post_install_message:
|
24
56
|
rdoc_options: []
|