fluent-plugin-rds-slowlog 0.0.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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-rds-slowlog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 kenjiskywalker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # fluent-plugin-rds-slowlog
2
+
3
+
4
+
5
+ ## Overview
6
+ ***AWS RDS slow_log*** input plugin.
7
+
8
+ 1. **"SELECT * FROM slow_log"**
9
+ 2. **"CALL mysql.rds_rotate_slow_log"**
10
+
11
+ every 10 seconds from AWS RDS.
12
+
13
+ ## Configuration
14
+
15
+ ```config
16
+ <source>
17
+ type rds_slowlog
18
+ tag rds-slowlog
19
+ host [RDS Hostname]
20
+ username [RDS Username]
21
+ password [RDS Password]
22
+ </source>
23
+ ```
24
+
25
+ ### Example GET RDS slow_log
26
+
27
+ ```config
28
+ <source>
29
+ type rds_slowlog
30
+ tag rds-slowlog
31
+ host [RDS Hostname]
32
+ username [RDS Username]
33
+ password [RDS Password]
34
+ </source>
35
+
36
+ <match rds-slowlog>
37
+ type copy
38
+ <store>
39
+ type file
40
+ path /var/log/slow_log
41
+ </store>
42
+ </match>
43
+ ```
44
+
45
+ #### output data format
46
+
47
+ ```
48
+ 2013-03-08T16:04:43+09:00 rds-slowlog {"start_time":"2013-03-08 07:04:38","user_host":"rds_db[rds_db] @ [192.0.2.10]","query_time":"00:00:00","lock_time":"00:00:00","rows_sent":"3000","rows_examined":"3000","db":"rds_db","last_insert_id":"0","insert_id":"0","server_id":"100000000","sql_text":"select foo from bar"}
49
+ 2013-03-08T16:04:43+09:00 rds-slowlog {"start_time":"2013-03-08 07:04:38","user_host":"rds_db[rds_db] @ [192.0.2.10]","query_time":"00:00:00","lock_time":"00:00:00","rows_sent":"3000","rows_examined":"3000","db":"rds_db","last_insert_id":"0","insert_id":"0","server_id":"100000000","sql_text":"Quit"}
50
+ ```
51
+
52
+ ## TODO
53
+
54
+ * more test test test
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "fluent-plugin-rds-slowlog"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["kenjiskywalker"]
9
+ gem.email = ["git@kenjiskywalker.org"]
10
+ gem.description = "Amazon RDS slow_log input plugin for Fluent event collector"
11
+ gem.homepage = "https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog"
12
+ gem.summary = gem.description
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+ gem.add_dependency "fluentd", "~> 0.10.30"
18
+ gem.add_dependency "mysql2", "~> 0.3.11"
19
+ end
@@ -0,0 +1,54 @@
1
+ class Fluent::Rds_SlowlogInput < Fluent::Input
2
+ Fluent::Plugin.register_input("rds_slowlog", self)
3
+
4
+ config_param :tag, :string
5
+ config_param :host, :string, :default => nil
6
+ config_param :port, :integer, :default => 3306
7
+ config_param :username, :string, :default => nil
8
+ config_param :password, :string, :default => nil
9
+
10
+ def initialize
11
+ super
12
+ require 'mysql2'
13
+ end
14
+
15
+ def configure(conf)
16
+ super
17
+ @client = Mysql2::Client.new({
18
+ :host => @host,
19
+ :port => @port,
20
+ :username => @username,
21
+ :password => @password,
22
+ :database => 'mysql'
23
+ })
24
+ end
25
+
26
+ def start
27
+ super
28
+ @watcher = Thread.new(&method(:watch))
29
+ end
30
+
31
+ def shutdown
32
+ super
33
+ @watcher.terminate
34
+ @watcher.join
35
+ end
36
+
37
+ private
38
+ def watch
39
+ while true
40
+ sleep 10
41
+ output
42
+ end
43
+ end
44
+
45
+ def output
46
+ slow_log_data = {}
47
+ slow_log_data = @client.query('SELECT * FROM slow_log', :cast => false)
48
+ @client.query('CALL mysql.rds_rotate_slow_log')
49
+
50
+ slow_log_data.each do |row|
51
+ Fluent::Engine.emit(tag, Fluent::Engine.now, row)
52
+ end
53
+ end
54
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require "test/unit"
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require "fluent/test"
16
+ unless ENV.has_key?("VERBOSE")
17
+ nulllogger = Object.new
18
+ nulllogger.instance_eval {|obj|
19
+ def method_missing(method, *args)
20
+ #pass
21
+ end
22
+ }
23
+ $log = nulllogger
24
+ end
25
+
26
+ require "fluent/plugin/in_rds_slowlog"
27
+
28
+ class Test::Unit::TestCase
29
+ end
30
+
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ class Rds_SlowlogInputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ tag rds-slowlog
10
+ host localhost
11
+ username test_rds_user
12
+ password test_rds_password
13
+ ]
14
+
15
+ def create_driver(conf = CONFIG)
16
+ Fluent::Test::InputTestDriver.new(Fluent::Rds_SlowlogInput).configure(conf)
17
+ end
18
+
19
+ def test_configure
20
+ d = create_driver
21
+ assert_equal 'rds-slowlog', d.instance.tag
22
+ assert_equal 'localhost', d.instance.host
23
+ assert_equal 'test_rds_user', d.instance.username
24
+ assert_equal 'test_rds_password', d.instance.password
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-rds-slowlog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kenjiskywalker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-09 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.10.30
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.10.30
30
+ - !ruby/object:Gem::Dependency
31
+ name: mysql2
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.3.11
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.3.11
46
+ description: Amazon RDS slow_log input plugin for Fluent event collector
47
+ email:
48
+ - git@kenjiskywalker.org
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - fluent-plugin-rds-slowlog.gemspec
59
+ - lib/fluent/plugin/in_rds_slowlog.rb
60
+ - test/helper.rb
61
+ - test/plugin/test_in_rds_slowlog.rb
62
+ homepage: https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Amazon RDS slow_log input plugin for Fluent event collector
86
+ test_files:
87
+ - test/helper.rb
88
+ - test/plugin/test_in_rds_slowlog.rb