fluent-plugin-rds-log 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f633e9b5d80f11e10825cac2bd9e29b079637ef
4
+ data.tar.gz: 16c9681a9a0a56839fbe035b4988cd15d3ac5855
5
+ SHA512:
6
+ metadata.gz: 049cde9472c2d179129911c9694519af1b3efdff348dcad275fc59f2fe60addfdc7b938ee447a539dcce010c1a9a8ee8fac4f032112391953e4b18495601cae7
7
+ data.tar.gz: 9ee61866b3ab4b921bdb1f90237b49f229beccbe9dbe2b3582f4c8e260731e24e2aca8956075916f9890bbcc29330053755e804ddab94ffc7ff4799a1e0df42e
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/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - rbx-19mode
8
+
9
+ branches:
10
+ only:
11
+ - master
12
+
13
+ script: bundle exec rake test
data/= ADDED
File without changes
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,69 @@
1
+ # fluent-plugin-rds-log (DEBUGGING NOW!!)
2
+
3
+ ## RDS Setting
4
+
5
+ [Working with MySQL Database Log Files / aws documentation](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html)
6
+
7
+ - Set the `slow_query_log` parameter to `1`
8
+ - setting `min_examined_row_limit`
9
+ - setting `long_query_time`
10
+
11
+ ## Overview
12
+ ***AWS RDS slow_log*** input plugin.
13
+
14
+ 1. **"SELECT * FROM slow_log"**
15
+ 2. **"CALL mysql.rds_rotate_slow_log"**
16
+
17
+ every 10 seconds from AWS RDS.
18
+
19
+ ## Configuration
20
+
21
+ ```config
22
+ <source>
23
+ type rds_slowlog
24
+ tag rds-slowlog
25
+ host [RDS Hostname]
26
+ username [RDS Username]
27
+ password [RDS Password]
28
+ log_type {slow_log|general_log}
29
+ refresh_interval 30
30
+ </source>
31
+ ```
32
+
33
+ ### Example GET RDS slow_log
34
+
35
+ ```config
36
+ <source>
37
+ type rds_slowlog
38
+ tag rds-slowlog
39
+ host [RDS Hostname]
40
+ username [RDS Username]
41
+ password [RDS Password]
42
+ log_type slow_log
43
+ refresh_interval 10
44
+ </source>
45
+
46
+ <match rds-slowlog>
47
+ type copy
48
+ <store>
49
+ type file
50
+ path /var/log/slow_log
51
+ </store>
52
+ </match>
53
+ ```
54
+
55
+ #### output data format
56
+
57
+ ```
58
+ 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"}
59
+ 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"}
60
+ ```
61
+
62
+ #### if not connect
63
+
64
+ - td-agent.log
65
+
66
+ ```
67
+ 2013-06-29 00:32:55 +0900 [error]: fluent-plugin-rds-log: cannot connect RDS
68
+ ```
69
+
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,20 @@
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-log"
7
+ gem.version = "0.1.0"
8
+ gem.authors = ["shinsaka"]
9
+ gem.email = ["shinx1265@gmail.com"]
10
+ gem.description = "Amazon RDS slow_log and general_log input plugin for Fluent event collector"
11
+ gem.homepage = "https://github.com/shinsaka/fluent-plugin-rds-log"
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
+ gem.add_development_dependency "rake", ">= 10.0.4"
20
+ end
@@ -0,0 +1,62 @@
1
+ class Fluent::Rds_LogInput < Fluent::Input
2
+ Fluent::Plugin.register_input("rds_log", 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
+ config_param :log_type, :string, :default => nil
10
+ config_param :refresh_interval, :integer, :default => 30
11
+
12
+ def initialize
13
+ super
14
+ require 'mysql2'
15
+ end
16
+
17
+ def configure(conf)
18
+ super
19
+ if @log_type.empty?
20
+ $log.error "fluent-plugin-rds-log: missing parameter log_type is {slow_log|general_log}"
21
+ end
22
+ begin
23
+ @client = Mysql2::Client.new({
24
+ :host => @host,
25
+ :port => @port,
26
+ :username => @username,
27
+ :password => @password,
28
+ :database => 'mysql'
29
+ })
30
+ rescue
31
+ $log.error "fluent-plugin-rds-log: cannot connect RDS"
32
+ end
33
+ end
34
+
35
+ def start
36
+ super
37
+ @watcher = Thread.new(&method(:watch))
38
+ end
39
+
40
+ def shutdown
41
+ super
42
+ @watcher.terminate
43
+ @watcher.join
44
+ end
45
+
46
+ private
47
+ def watch
48
+ while true
49
+ sleep @refresh_interval
50
+ output
51
+ end
52
+ end
53
+
54
+ def output
55
+ @client.query("CALL mysql.rds_rotate_#{@log_type}")
56
+
57
+ output_log_data = @client.query("SELECT * FROM mysql.#{@log_type}_backup", :cast => false)
58
+ output_log_data.each do |row|
59
+ Fluent::Engine.emit(tag, Fluent::Engine.now, row)
60
+ end
61
+ end
62
+ 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,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-rds-log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shinsaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.30
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.30
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.11
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.11
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 10.0.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 10.0.4
55
+ description: Amazon RDS slow_log and general_log input plugin for Fluent event collector
56
+ email:
57
+ - shinx1265@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - '='
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - fluent-plugin-rds-log.gemspec
70
+ - lib/fluent/plugin/in_rds_log.rb
71
+ - test/helper.rb
72
+ - test/plugin/test_in_rds_slowlog.rb
73
+ homepage: https://github.com/shinsaka/fluent-plugin-rds-log
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Amazon RDS slow_log and general_log input plugin for Fluent event collector
96
+ test_files:
97
+ - test/helper.rb
98
+ - test/plugin/test_in_rds_slowlog.rb