fluent-plugin-pghstore 0.1.0 → 0.1.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/fluent-plugin-pghstore.gemspec +1 -1
- data/lib/fluent/plugin/out_pghstore.rb +25 -13
- metadata +2 -2
@@ -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-pghstore"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.1"
|
7
7
|
s.authors = ["WAKAYAMA Shirou"]
|
8
8
|
s.email = ["shirou.faw@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/shirou/fluent-plugin-pghstore"
|
@@ -18,16 +18,12 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
18
18
|
def start
|
19
19
|
super
|
20
20
|
|
21
|
-
@conn = get_connection(@database, @host, @port, @user, @password)
|
22
|
-
|
23
21
|
create_table(@table) unless table_exists?(@table)
|
24
|
-
|
25
22
|
end
|
26
23
|
|
27
24
|
def shutdown
|
28
25
|
super
|
29
26
|
|
30
|
-
@conn.close
|
31
27
|
end
|
32
28
|
|
33
29
|
def format(tag, time, record)
|
@@ -35,14 +31,21 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
35
31
|
end
|
36
32
|
|
37
33
|
def write(chunk)
|
34
|
+
conn = get_connection()
|
35
|
+
if conn == nil
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
38
39
|
chunk.msgpack_each {|(tag, time_str, record)|
|
39
40
|
sql = generate_sql(tag, time_str, record)
|
40
41
|
begin
|
41
|
-
|
42
|
+
conn.exec(sql)
|
42
43
|
rescue PGError => e
|
43
44
|
$log.error "PGError: " + e.message # throw away
|
44
45
|
end
|
46
|
+
|
45
47
|
}
|
48
|
+
conn.close
|
46
49
|
end
|
47
50
|
|
48
51
|
private
|
@@ -64,12 +67,17 @@ SQL
|
|
64
67
|
return sql
|
65
68
|
end
|
66
69
|
|
67
|
-
def get_connection(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
def get_connection()
|
71
|
+
begin
|
72
|
+
if @user
|
73
|
+
return PG.connect(:dbname => @database, :host => @host, :port => @port,
|
74
|
+
:user => @user, :password => @password)
|
75
|
+
else
|
76
|
+
return PG.connect(:dbname => @database, :host => @host, :port => @port)
|
77
|
+
end
|
78
|
+
rescue PGError => e
|
79
|
+
$log.error "Error: could not connect database:" + @database
|
80
|
+
return nil
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
@@ -77,7 +85,9 @@ SQL
|
|
77
85
|
sql =<<"SQL"
|
78
86
|
SELECT COUNT(*) FROM pg_tables WHERE tablename = '#{table}';
|
79
87
|
SQL
|
80
|
-
|
88
|
+
conn = get_connection()
|
89
|
+
res = conn.exec(sql)
|
90
|
+
conn.close
|
81
91
|
if res[0]["count"] == "1"
|
82
92
|
return true
|
83
93
|
else
|
@@ -96,7 +106,9 @@ SQL
|
|
96
106
|
|
97
107
|
sql += @table_option if @table_option
|
98
108
|
|
99
|
-
|
109
|
+
conn = get_connection()
|
110
|
+
conn.exec(sql)
|
111
|
+
conn.close
|
100
112
|
|
101
113
|
$log.warn "#{tablename} table is not exists. created."
|
102
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-pghstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|