fluent-plugin-pgjson 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -1
- data/fluent-plugin-pgjson.gemspec +1 -1
- data/lib/fluent/plugin/out_pgjson.rb +18 -32
- metadata +12 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a690b321412f2b0fe7dd2537e38c284b3d6753ee
|
4
|
+
data.tar.gz: abed844423a52e625fc1798231224df083b7e8ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 933ee51523a63e67430316e12b0c22119d51d1e20a659e6b909bfdd63e8e6852c38f56cf85f6737b7f436e4915570617db6bcba9dc3e44a88962b669410b2e8a
|
7
|
+
data.tar.gz: 9f9b7c82bcc74e005b03abe6e98b6e496821407a4adbc8a9314702cc090ac373b93ec7b03bd2195d88f17db8bbefe60c9c3edb1e997d18f66ab0eed0d3929df2
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-pgjson"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.5"
|
7
7
|
s.authors = ["OKUNO Akihiro"]
|
8
8
|
s.email = ["choplin.choplin@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/choplin/fluent-plugin-pgjson"
|
@@ -13,6 +13,7 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
13
13
|
config_param :time_col , :string , :default => 'time'
|
14
14
|
config_param :tag_col , :string , :default => 'tag'
|
15
15
|
config_param :record_col , :string , :default => 'record'
|
16
|
+
config_param :messagepack, :bool , :default => false
|
16
17
|
|
17
18
|
def initialize
|
18
19
|
super
|
@@ -22,7 +23,6 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
22
23
|
|
23
24
|
def configure(conf)
|
24
25
|
super
|
25
|
-
@stmt_name = 'insert'
|
26
26
|
end
|
27
27
|
|
28
28
|
def shutdown
|
@@ -40,56 +40,42 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
40
40
|
def write(chunk)
|
41
41
|
begin
|
42
42
|
init_connection
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
begin
|
47
|
-
@conn.close()
|
48
|
-
rescue
|
43
|
+
@conn.exec("COPY #{@table} (#{@tag_col}, #{@time_col}, #{@record_col}) FROM STDIN WITH DELIMITER E'\\x01'")
|
44
|
+
chunk.msgpack_each do |tag, time, record|
|
45
|
+
@conn.put_copy_data "#{tag}\x01#{Time.at(time).to_s}\x01#{record_value(record)}\n"
|
49
46
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
@conn.put_copy_end
|
48
|
+
rescue
|
49
|
+
@conn.close()
|
50
|
+
@conn = nil
|
51
|
+
raise "failed to send data to postgres: #$!"
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
55
|
private
|
57
56
|
def init_connection
|
58
57
|
if @conn.nil?
|
59
|
-
$log.debug "
|
58
|
+
$log.debug "connecting to PostgreSQL server #{@host}:#{@port}, database #{@database}..."
|
60
59
|
|
61
60
|
begin
|
62
61
|
@conn = PGconn.new(:dbname => @database, :host => @host, :port => @port, :sslmode => @sslmode, :user => @user, :password => @password)
|
63
62
|
@conn.setnonblocking(true)
|
64
63
|
rescue
|
65
64
|
if ! @conn.nil?
|
66
|
-
|
67
|
-
|
68
|
-
rescue
|
69
|
-
end
|
70
|
-
|
71
|
-
@conn - nil
|
65
|
+
@conn.close()
|
66
|
+
@conn = nil
|
72
67
|
end
|
73
|
-
|
74
|
-
raise
|
68
|
+
raise "failed to initialize connection: #$!"
|
75
69
|
end
|
76
70
|
end
|
77
71
|
end
|
78
72
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
SQL
|
85
|
-
end
|
86
|
-
|
87
|
-
def build_values(chunk)
|
88
|
-
tmp = []
|
89
|
-
chunk.msgpack_each do |tag, time, record|
|
90
|
-
tmp << ("("+[tag, Time.at(time), record.to_json].map{|s| @conn.escape_literal(s.to_s)}.join(',')+")")
|
73
|
+
def record_value(record)
|
74
|
+
if @msgpack
|
75
|
+
"\\#{@conn.escape_bytea(record.to_msgpack)}"
|
76
|
+
else
|
77
|
+
record.to_json
|
91
78
|
end
|
92
|
-
tmp.join(',')
|
93
79
|
end
|
94
80
|
end
|
95
81
|
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-pgjson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- OKUNO Akihiro
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: fluentd
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: pg
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: ''
|
@@ -50,7 +45,7 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
53
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
54
49
|
- Gemfile
|
55
50
|
- LICENSE
|
56
51
|
- README.md
|
@@ -62,29 +57,27 @@ files:
|
|
62
57
|
- test/plugin/test_out.rb
|
63
58
|
homepage: https://github.com/choplin/fluent-plugin-pgjson
|
64
59
|
licenses: []
|
60
|
+
metadata: {}
|
65
61
|
post_install_message:
|
66
62
|
rdoc_options: []
|
67
63
|
require_paths:
|
68
64
|
- lib
|
69
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
66
|
requirements:
|
72
|
-
- -
|
67
|
+
- - ">="
|
73
68
|
- !ruby/object:Gem::Version
|
74
69
|
version: '0'
|
75
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
71
|
requirements:
|
78
|
-
- -
|
72
|
+
- - ">="
|
79
73
|
- !ruby/object:Gem::Version
|
80
74
|
version: '0'
|
81
75
|
requirements: []
|
82
76
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.2.2
|
84
78
|
signing_key:
|
85
|
-
specification_version:
|
79
|
+
specification_version: 4
|
86
80
|
summary: ''
|
87
81
|
test_files:
|
88
82
|
- test/helper.rb
|
89
83
|
- test/plugin/test_out.rb
|
90
|
-
has_rdoc:
|