fluent-plugin-rds-slowlog 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/fluent-plugin-rds-slowlog.gemspec +1 -1
- data/lib/fluent/plugin/in_rds_slowlog.rb +15 -6
- data/test/plugin/test_in_rds_slowlog.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db90bf646e818655b609cd6ce8f33f8995596dfa
|
4
|
+
data.tar.gz: 16113ed4766d26efcfbf5478bba553d914af5338
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca01b38aaa6d05181f8394f78071beff0b34a973c666b397d183cdb25e643aca4112d586f31d912613f160d0cefcbf076ff0ae55ba9f51582b6a333ba7e9c025
|
7
|
+
data.tar.gz: 326da4ace80776fd2f80f1729fa6f351e952014a72967bc8f6b2e2e3cc7216ff1293fb483c4f3eb6683f5f27fb8573b3b5823fa5d3688ebbd1b7f52675108f0e
|
data/README.md
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
|
15
15
|
1. **"CALL mysql.rds_rotate_slow_log"**
|
16
16
|
2. **"SELECT * FROM slow_log_backup"**
|
17
|
+
3. **"INSERT INTO yourdb.slow_log_custom_backup SELECT * FROM slow_log_backup"** (if you want to take a backup)
|
17
18
|
|
18
19
|
every 10 seconds from AWS RDS.
|
19
20
|
|
@@ -26,6 +27,7 @@ every 10 seconds from AWS RDS.
|
|
26
27
|
host [RDS Hostname]
|
27
28
|
username [RDS Username]
|
28
29
|
password [RDS Password]
|
30
|
+
backup_table [Your Backup Tablename]
|
29
31
|
</source>
|
30
32
|
```
|
31
33
|
|
@@ -39,6 +41,7 @@ every 10 seconds from AWS RDS.
|
|
39
41
|
username [RDS Username]
|
40
42
|
password [RDS Password]
|
41
43
|
interval 10
|
44
|
+
backup_table [Your Backup Tablename]
|
42
45
|
</source>
|
43
46
|
|
44
47
|
<match rds-slowlog>
|
@@ -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-slowlog"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.7"
|
8
8
|
gem.authors = ["kenjiskywalker", "winebarrel"]
|
9
9
|
gem.email = ["git@kenjiskywalker.org", "sgwr_dts@yahoo.co.jp"]
|
10
10
|
gem.description = "Amazon RDS slow_log input plugin for Fluent event collector"
|
@@ -11,12 +11,13 @@ class Fluent::Rds_SlowlogInput < Fluent::Input
|
|
11
11
|
define_method("router") { Fluent::Engine }
|
12
12
|
end
|
13
13
|
|
14
|
-
config_param :tag,
|
15
|
-
config_param :host,
|
16
|
-
config_param :port,
|
17
|
-
config_param :username,
|
18
|
-
config_param :password,
|
19
|
-
config_param :interval,
|
14
|
+
config_param :tag, :string
|
15
|
+
config_param :host, :string, :default => nil
|
16
|
+
config_param :port, :integer, :default => 3306
|
17
|
+
config_param :username, :string, :default => nil
|
18
|
+
config_param :password, :string, :default => nil, :secret => true
|
19
|
+
config_param :interval, :integer, :default => 10
|
20
|
+
config_param :backup_table, :string, :default => nil
|
20
21
|
|
21
22
|
def initialize
|
22
23
|
super
|
@@ -40,6 +41,10 @@ class Fluent::Rds_SlowlogInput < Fluent::Input
|
|
40
41
|
|
41
42
|
def start
|
42
43
|
super
|
44
|
+
if @backup_table
|
45
|
+
@client.query("CREATE TABLE IF NOT EXISTS #{@backup_table} LIKE slow_log")
|
46
|
+
end
|
47
|
+
|
43
48
|
@loop = Coolio::Loop.new
|
44
49
|
timer = TimerWatcher.new(@interval, true, log, &method(:output))
|
45
50
|
@loop.attach(timer)
|
@@ -70,6 +75,10 @@ class Fluent::Rds_SlowlogInput < Fluent::Input
|
|
70
75
|
row.each_key {|key| row[key].force_encoding(Encoding::ASCII_8BIT) if row[key].is_a?(String)}
|
71
76
|
router.emit(tag, Fluent::Engine.now, row)
|
72
77
|
end
|
78
|
+
|
79
|
+
if @backup_table
|
80
|
+
@client.query("INSERT INTO #{@backup_table} SELECT * FROM slow_log_backup")
|
81
|
+
end
|
73
82
|
end
|
74
83
|
|
75
84
|
class TimerWatcher < Coolio::TimerWatcher
|
@@ -36,6 +36,7 @@ class Rds_SlowlogInputTest < Test::Unit::TestCase
|
|
36
36
|
client = mysql2_client
|
37
37
|
client.query("DROP USER test_rds_user@localhost")
|
38
38
|
client.query("DROP PROCEDURE `mysql`.`rds_rotate_slow_log`")
|
39
|
+
client.query("DROP TABLE `mysql`.`slow_log_custom_backup`")
|
39
40
|
end
|
40
41
|
|
41
42
|
def insert_slow_log_sql
|
@@ -87,6 +88,7 @@ class Rds_SlowlogInputTest < Test::Unit::TestCase
|
|
87
88
|
username test_rds_user
|
88
89
|
password test_rds_password
|
89
90
|
interval 0
|
91
|
+
backup_table mysql.slow_log_custom_backup
|
90
92
|
]
|
91
93
|
|
92
94
|
def create_driver(conf = CONFIG)
|
@@ -100,6 +102,7 @@ class Rds_SlowlogInputTest < Test::Unit::TestCase
|
|
100
102
|
assert_equal 'test_rds_user', d.instance.username
|
101
103
|
assert_equal 'test_rds_password', d.instance.password
|
102
104
|
assert_equal 0, d.instance.interval
|
105
|
+
assert_equal 'mysql.slow_log_custom_backup', d.instance.backup_table
|
103
106
|
end
|
104
107
|
|
105
108
|
def test_output
|
@@ -116,4 +119,26 @@ class Rds_SlowlogInputTest < Test::Unit::TestCase
|
|
116
119
|
["rds-slowlog", 1432492200, {"start_time"=>"2015-09-29 15:43:45", "user_host"=>"root@localhost", "query_time"=>"00:00:00", "lock_time"=>"00:00:00", "rows_sent"=>"0", "rows_examined"=>"0", "db"=>"employees", "last_insert_id"=>"0", "insert_id"=>"0", "server_id"=>"1", "sql_text"=>"SELECT 2", "thread_id"=>"0"}],
|
117
120
|
], records
|
118
121
|
end
|
122
|
+
|
123
|
+
def test_backup
|
124
|
+
d = create_driver
|
125
|
+
d.run
|
126
|
+
|
127
|
+
records = []
|
128
|
+
client = self.class.mysql2_client
|
129
|
+
slow_logs = client.query('SELECT * FROM `mysql`.`slow_log_custom_backup`', :cast => false)
|
130
|
+
slow_logs.each do |row|
|
131
|
+
row.each_key {|key| row[key].force_encoding(Encoding::ASCII_8BIT) if row[key].is_a?(String)}
|
132
|
+
records.push(row)
|
133
|
+
end
|
134
|
+
|
135
|
+
unless self.class.has_thread_id?
|
136
|
+
records.each {|r| r["thread_id"] = "0" }
|
137
|
+
end
|
138
|
+
|
139
|
+
assert_equal [
|
140
|
+
{"start_time"=>"2015-09-29 15:43:44", "user_host"=>"root@localhost", "query_time"=>"00:00:00", "lock_time"=>"00:00:00", "rows_sent"=>"0", "rows_examined"=>"0", "db"=>"employees", "last_insert_id"=>"0", "insert_id"=>"0", "server_id"=>"1", "sql_text"=>"SELECT 1", "thread_id"=>"0"},
|
141
|
+
{"start_time"=>"2015-09-29 15:43:45", "user_host"=>"root@localhost", "query_time"=>"00:00:00", "lock_time"=>"00:00:00", "rows_sent"=>"0", "rows_examined"=>"0", "db"=>"employees", "last_insert_id"=>"0", "insert_id"=>"0", "server_id"=>"1", "sql_text"=>"SELECT 2", "thread_id"=>"0"},
|
142
|
+
], records
|
143
|
+
end
|
119
144
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-rds-slowlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kenjiskywalker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|