fluent-plugin-rds-log 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/fluent-plugin-rds-log.gemspec +1 -1
- data/lib/fluent/plugin/in_rds_log.rb +16 -21
- metadata +2 -2
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "fluent-plugin-rds-log"
|
7
|
-
gem.version = "0.1.
|
7
|
+
gem.version = "0.1.5"
|
8
8
|
gem.authors = ["shinsaka"]
|
9
9
|
gem.email = ["shinx1265@gmail.com"]
|
10
10
|
gem.description = "Amazon RDS slow_log and general_log input plugin for Fluent event collector"
|
@@ -35,16 +35,9 @@ class Fluent::Rds_LogInput < Fluent::Input
|
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
|
-
def connect_all
|
39
|
-
@clients = {}
|
40
|
-
@host.split(',').each do |host|
|
41
|
-
@clients[host] = connect(host)
|
42
|
-
end
|
43
|
-
end
|
44
38
|
|
45
39
|
def connect(host)
|
46
40
|
begin
|
47
|
-
$log.info "fluent-plugin-rds-log: connecting RDS [#{host}]"
|
48
41
|
client = Mysql2::Client.new({
|
49
42
|
:host => host,
|
50
43
|
:port => @port,
|
@@ -53,39 +46,41 @@ class Fluent::Rds_LogInput < Fluent::Input
|
|
53
46
|
:reconnect => @auto_reconnect,
|
54
47
|
:database => 'mysql'
|
55
48
|
})
|
56
|
-
$log.info "fluent-plugin-rds-log: connected RDS [#{host}]"
|
57
49
|
return client
|
58
50
|
rescue
|
59
51
|
$log.error "fluent-plugin-rds-log: cannot connect RDS [#{host}]"
|
60
52
|
end
|
53
|
+
return nil
|
61
54
|
end
|
62
55
|
|
63
56
|
def watch
|
64
|
-
connect_all
|
65
57
|
while true
|
66
|
-
sleep @refresh_interval
|
67
58
|
@host.split(',').each do |host|
|
68
59
|
output(host)
|
69
60
|
end
|
61
|
+
sleep @refresh_interval
|
70
62
|
end
|
71
63
|
end
|
72
64
|
|
73
65
|
def output(host)
|
74
|
-
client =
|
75
|
-
if client.nil?
|
76
|
-
|
77
|
-
if client.nil?
|
78
|
-
return
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
client.query("CALL mysql.rds_rotate_#{@log_type}")
|
83
|
-
|
84
|
-
output_log_data = client.query("SELECT * FROM mysql.#{@log_type}_backup", :cast => false)
|
66
|
+
client = connect(host)
|
67
|
+
return if client.nil?
|
68
|
+
output_log_data = query(client)
|
85
69
|
output_log_data.each do |row|
|
86
70
|
row.delete_if{|key,value| value == ''}
|
87
71
|
row['host'] = host if @add_host
|
88
72
|
Fluent::Engine.emit(tag, Fluent::Engine.now, row)
|
89
73
|
end
|
74
|
+
client.close
|
75
|
+
end
|
76
|
+
|
77
|
+
def query(client)
|
78
|
+
begin
|
79
|
+
client.query("CALL mysql.rds_rotate_#{@log_type}")
|
80
|
+
output_log_data = client.query("SELECT * FROM mysql.#{@log_type}_backup", :cast => false)
|
81
|
+
rescue Exception => e
|
82
|
+
$log.error "fluent-plugin-rds-log: ERROR Occurred!"
|
83
|
+
$log.error "#{e.message}\n#{e.backtrace.join("\n")}"
|
84
|
+
end
|
90
85
|
end
|
91
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-rds-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
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: 2015-05-
|
12
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|