fluent-plugin-mysql-query 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19011ab6e44bb3ce1711bcac6f1bf1052364ca1d
4
+ data.tar.gz: 5601aa756c94e9386cae4927d3e5fe2597ddb480
5
+ SHA512:
6
+ metadata.gz: 2c44650fb0c06d5198566c2706d089f76ef76378560fcc52cc0287aca7be05ae2cb60e0c887ab85f405fea0ed807787a5b2a69413c214434b8cd0e8476334a35
7
+ data.tar.gz: cacaa5f3e27e44a7e08740167e4738baad00e5de945efdc9aca9a2e33de514e8f598afae7b2d2164541efffbc6541e530dbd7cdd89d2918c4e6b027c5f2f5f92
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1
5
- - 2.0.0
6
- - 1.9.3
4
+ - 2.4.1
5
+ - 2.3.4
6
+ - 2.2.5
7
+ - 2.1.10
data/README.md CHANGED
@@ -3,6 +3,13 @@ fluent-plugin-mysql-query [![Build Status](https://travis-ci.org/y-ken/fluent-pl
3
3
 
4
4
  Fluentd Input plugin to execute mysql query and fetch rows. It is useful for stationary interval metrics measurement.
5
5
 
6
+ ## Requirements
7
+
8
+ | fluent-plugin-mysql | fluentd | ruby |
9
+ |---------------------|------------|--------|
10
+ | >= 0.4.0 | >= v0.14.0 | >= 2.1 |
11
+ | < 0.4.0 | >= v0.12.0 | >= 1.9 |
12
+
6
13
  ## Installation
7
14
 
8
15
  install with gem or fluent-gem command as:
@@ -20,7 +27,7 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mysql-query
20
27
  ### Config Sample
21
28
  `````
22
29
  <source>
23
- type mysql_query
30
+ @type mysql_query
24
31
  host localhost # Optional (default: localhost)
25
32
  port 3306 # Optional (default: 3306)
26
33
  username nagios # Optional (default: root)
@@ -39,7 +46,7 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mysql-query
39
46
  </source>
40
47
 
41
48
  <match input.mysql>
42
- type stdout
49
+ @type stdout
43
50
  </match>
44
51
  `````
45
52
 
@@ -1,9 +1,8 @@
1
- # -*- encoding: utf-8 -*-
2
1
  $:.push File.expand_path("../lib", __FILE__)
3
2
 
4
3
  Gem::Specification.new do |s|
5
4
  s.name = "fluent-plugin-mysql-query"
6
- s.version = "0.3.0"
5
+ s.version = "1.0.0"
7
6
  s.license = "Apache-2.0"
8
7
  s.authors = ["Kentaro Yoshida"]
9
8
  s.email = ["y.ken.studio@gmail.com"]
@@ -16,6 +15,7 @@ Gem::Specification.new do |s|
16
15
  s.require_paths = ["lib"]
17
16
 
18
17
  s.add_development_dependency "rake"
19
- s.add_runtime_dependency "fluentd"
18
+ s.add_development_dependency "test-unit", ">= 3.1.0"
19
+ s.add_runtime_dependency "fluentd", "> 0.14.0", "< 2"
20
20
  s.add_runtime_dependency "mysql2"
21
21
  end
@@ -1,26 +1,26 @@
1
- module Fluent
2
- class MysqlQueryInput < Fluent::Input
3
- Plugin.register_input('mysql_query', self)
1
+ require 'fluent/plugin/input'
2
+ require 'mysql2'
4
3
 
5
- def initialize
6
- require 'mysql2'
7
- super
8
- end
4
+ module Fluent::Plugin
5
+ class MysqlQueryInput < Fluent::Plugin::Input
6
+ Fluent::Plugin.register_input('mysql_query', self)
9
7
 
10
- config_param :host, :string, :default => 'localhost'
11
- config_param :port, :integer, :default => 3306
12
- config_param :username, :string, :default => 'root'
13
- config_param :password, :string, :default => nil
14
- config_param :database, :string, :default => nil
15
- config_param :encoding, :string, :default => 'utf8'
16
- config_param :interval, :time, :default => '1m'
8
+ helpers :timer
9
+
10
+ config_param :host, :string, default: 'localhost'
11
+ config_param :port, :integer, default: 3306
12
+ config_param :username, :string, default: 'root'
13
+ config_param :password, :string, default: nil, secret: true
14
+ config_param :database, :string, default: nil
15
+ config_param :encoding, :string, default: 'utf8'
16
+ config_param :interval, :time, default: '1m'
17
17
  config_param :tag, :string
18
18
  config_param :query, :string
19
- config_param :nest_result, :bool, :default => false
20
- config_param :nest_key, :string, :default => 'result'
21
- config_param :row_count, :bool, :default => false
22
- config_param :row_count_key, :string, :default => 'row_count'
23
- config_param :record_hostname, :bool, :default => false
19
+ config_param :nest_result, :bool, default: false
20
+ config_param :nest_key, :string, default: 'result'
21
+ config_param :row_count, :bool, default: false
22
+ config_param :row_count_key, :string, default: 'row_count'
23
+ config_param :record_hostname, :bool, default: false
24
24
 
25
25
  def configure(conf)
26
26
  super
@@ -29,46 +29,40 @@ module Fluent
29
29
  end
30
30
 
31
31
  def start
32
- @thread = Thread.new(&method(:run))
33
- end
34
-
35
- def shutdown
36
- Thread.kill(@thread)
32
+ super
33
+ timer_execute(:in_mysql_query, @interval, &method(:on_timer))
37
34
  end
38
35
 
39
- def run
40
- loop do
41
- @hostname = get_mysql_hostname if @hostname.nil?
42
- tag = "#{@tag}".gsub('__HOSTNAME__', @hostname).gsub('${hostname}', @hostname)
43
- record = Hash.new
44
- record.store('hostname', @hostname) if @record_hostname
45
- result = get_exec_result
46
- record.store(@row_count_key, result.size) if @row_count
47
- if (@nest_result)
48
- record.store(@nest_key, result)
49
- Engine.emit(tag, Engine.now, record)
50
- else
51
- result.each do |data|
52
- Engine.emit(tag, Engine.now, record.merge(data))
53
- end
36
+ def on_timer
37
+ @hostname = get_mysql_hostname if @hostname.nil?
38
+ tag = "#{@tag}".gsub('__HOSTNAME__', @hostname).gsub('${hostname}', @hostname)
39
+ record = {}
40
+ record.store('hostname', @hostname) if @record_hostname
41
+ result = get_exec_result
42
+ record.store(@row_count_key, result.size) if @row_count
43
+ if (@nest_result)
44
+ record.store(@nest_key, result)
45
+ router.emit(tag, Fluent::Engine.now, record)
46
+ else
47
+ result.each do |data|
48
+ router.emit(tag, Fluent::Engine.now, record.merge(data))
54
49
  end
55
- sleep @interval
56
50
  end
57
51
  end
58
52
 
59
53
  def get_connection
60
54
  begin
61
55
  return Mysql2::Client.new({
62
- :host => @host,
63
- :port => @port,
64
- :username => @username,
65
- :password => @password,
66
- :database => @database,
67
- :encoding => @encoding,
68
- :reconnect => true
56
+ host: @host,
57
+ port: @port,
58
+ username: @username,
59
+ password: @password,
60
+ database: @database,
61
+ encoding: @encoding,
62
+ reconnect: true
69
63
  })
70
64
  rescue Exception => e
71
- $log.warn "mysql_query: #{e}"
65
+ log.warn "mysql_query: #{e}"
72
66
  sleep @interval
73
67
  retry
74
68
  end
@@ -77,9 +71,9 @@ module Fluent
77
71
  def query(query)
78
72
  @mysql ||= get_connection
79
73
  begin
80
- return @mysql.query(query, :cast => false, :cache_rows => false)
74
+ return @mysql.query(query, cast: false, cache_rows: false)
81
75
  rescue Exception => e
82
- $log.warn "mysql_query: #{e}"
76
+ log.warn "mysql_query: #{e}"
83
77
  sleep @interval
84
78
  retry
85
79
  end
@@ -89,10 +83,12 @@ module Fluent
89
83
  query("SHOW VARIABLES LIKE 'hostname'").each do |row|
90
84
  return row.fetch('Value')
91
85
  end
86
+ # hostname variable is not present
87
+ return ''
92
88
  end
93
89
 
94
90
  def get_exec_result
95
- result = Array.new
91
+ result = []
96
92
  stmt = query(@query)
97
93
  stmt.each do |row|
98
94
  result.push(row)
@@ -1,28 +1,14 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
1
+ require 'bundler/setup'
10
2
  require 'test/unit'
11
3
 
12
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
5
+ $LOAD_PATH.unshift(__dir__)
14
6
  require 'fluent/test'
15
- unless ENV.has_key?('VERBOSE')
16
- nulllogger = Object.new
17
- nulllogger.instance_eval {|obj|
18
- def method_missing(method, *args)
19
- # pass
20
- end
21
- }
22
- $log = nulllogger
23
- end
24
-
7
+ require 'fluent/test/helpers'
8
+ require 'fluent/test/driver/input'
25
9
  require 'fluent/plugin/in_mysql_query'
26
10
 
27
11
  class Test::Unit::TestCase
12
+ include Fluent::Test::Helpers
13
+ extend Fluent::Test::Helpers
28
14
  end
@@ -14,27 +14,32 @@ class MysqlQueryInputTest < Test::Unit::TestCase
14
14
  record_hostname yes
15
15
  ]
16
16
 
17
- def create_driver(conf=CONFIG,tag='test')
18
- Fluent::Test::OutputTestDriver.new(Fluent::MysqlQueryInput, tag).configure(conf)
17
+ def create_driver(conf=CONFIG)
18
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::MysqlQueryInput).configure(conf)
19
19
  end
20
20
 
21
- def test_configure
22
- assert_raise(Fluent::ConfigError) {
23
- d = create_driver('')
24
- }
25
- d = create_driver %[
26
- host localhost
27
- port 3306
28
- interval 30
29
- tag input.mysql
30
- query SHOW VARIABLES LIKE 'Thread_%'
31
- record_hostname yes
32
- ]
33
- assert_equal 'localhost', d.instance.host
34
- assert_equal 3306, d.instance.port
35
- assert_equal 30, d.instance.interval
36
- assert_equal 'input.mysql', d.instance.tag
37
- assert_equal true, d.instance.record_hostname
38
- assert_equal false, d.instance.nest_result
21
+ sub_test_case "configure" do
22
+ test "empty" do
23
+ assert_raise(Fluent::ConfigError) do
24
+ create_driver('')
25
+ end
26
+ end
27
+
28
+ test "simple" do
29
+ d = create_driver %[
30
+ host localhost
31
+ port 3306
32
+ interval 30
33
+ tag input.mysql
34
+ query SHOW VARIABLES LIKE 'Thread_%'
35
+ record_hostname yes
36
+ ]
37
+ assert_equal 'localhost', d.instance.host
38
+ assert_equal 3306, d.instance.port
39
+ assert_equal 30, d.instance.interval
40
+ assert_equal 'input.mysql', d.instance.tag
41
+ assert_equal true, d.instance.record_hostname
42
+ assert_equal false, d.instance.nest_result
43
+ end
39
44
  end
40
45
  end
metadata CHANGED
@@ -1,62 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mysql-query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kentaro Yoshida
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: fluentd
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">"
36
46
  - !ruby/object:Gem::Version
37
- version: '0'
47
+ version: 0.14.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '2'
38
51
  type: :runtime
39
52
  prerelease: false
40
53
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
54
  requirements:
43
- - - ! '>='
55
+ - - ">"
44
56
  - !ruby/object:Gem::Version
45
- version: '0'
57
+ version: 0.14.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '2'
46
61
  - !ruby/object:Gem::Dependency
47
62
  name: mysql2
48
63
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
64
  requirements:
51
- - - ! '>='
65
+ - - ">="
52
66
  - !ruby/object:Gem::Version
53
67
  version: '0'
54
68
  type: :runtime
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
71
  requirements:
59
- - - ! '>='
72
+ - - ">="
60
73
  - !ruby/object:Gem::Version
61
74
  version: '0'
62
75
  description:
@@ -66,8 +79,8 @@ executables: []
66
79
  extensions: []
67
80
  extra_rdoc_files: []
68
81
  files:
69
- - .gitignore
70
- - .travis.yml
82
+ - ".gitignore"
83
+ - ".travis.yml"
71
84
  - Gemfile
72
85
  - LICENSE.txt
73
86
  - README.md
@@ -79,27 +92,26 @@ files:
79
92
  homepage: https://github.com/y-ken/fluent-plugin-mysql-query
80
93
  licenses:
81
94
  - Apache-2.0
95
+ metadata: {}
82
96
  post_install_message:
83
97
  rdoc_options: []
84
98
  require_paths:
85
99
  - lib
86
100
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
101
  requirements:
89
- - - ! '>='
102
+ - - ">="
90
103
  - !ruby/object:Gem::Version
91
104
  version: '0'
92
105
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
106
  requirements:
95
- - - ! '>='
107
+ - - ">="
96
108
  - !ruby/object:Gem::Version
97
109
  version: '0'
98
110
  requirements: []
99
111
  rubyforge_project:
100
- rubygems_version: 1.8.23
112
+ rubygems_version: 2.2.5
101
113
  signing_key:
102
- specification_version: 3
114
+ specification_version: 4
103
115
  summary: Fluentd Input plugin to execute mysql query and fetch rows. It is useful
104
116
  for stationary interval metrics measurement.
105
117
  test_files: