fluent-plugin-mysqlslowquery 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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ #fluent-plugin-mysqlslowquery
2
+
3
+ Fluent input plugin for MySQL slow query log file.
4
+
5
+ ##How to use
6
+
7
+ Puts in_mysql_slow_query.rb to plugin directory.
8
+
9
+ ```shell
10
+ % cp in_mysql_slow_query.rb path/to/fluent/plugin
11
+ ```
12
+
13
+ Edit setting file.
14
+
15
+ ```shell
16
+ % edit fluent.conf
17
+ ```
18
+
19
+ ```
20
+ <source>
21
+ type mysql_slow_query
22
+ path /path/to/mysqld-slow.log
23
+ tag mysqld.slow_query
24
+ </source>
25
+ ```
26
+
27
+ ##Expected record format
28
+
29
+ Sample
30
+
31
+ ```
32
+ # Time: 111003 14:17:38
33
+ # User@Host: root[root] @ localhost []
34
+ # Query_time: 0.000270 Lock_time: 0.000097 Rows_sent: 1 Rows_examined: 0
35
+ SET timestamp=1317619058;
36
+ SELECT * FROM life;
37
+ ```
38
+
39
+ Then following JSON is going to be made.
40
+
41
+ ```json
42
+ {
43
+ "time": "2011-10-03 14:17:38",
44
+ "user": "root[root]",
45
+ "host": "localhost []",
46
+ "query_time": 0.000270,
47
+ "lock_time": 0.000097,
48
+ "rows_sent": 1,
49
+ "rows_examined": 0,
50
+ "sql": "select * from life;"
51
+ }
52
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- coding:utf-8 -*-
2
+ # -*- mode:ruby -*-
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["taka84u9"]
6
+ gem.email = ["taka84u9@gmail.com"]
7
+ gem.description = %q{Fluent input plugin for MySQL slow query log file.}
8
+ gem.summary = %q{Fluent input plugin for MySQL slow query log file.}
9
+ gem.homepage = "https://github.com/taka84u9/fluent-plugin-mysqlslowquery"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fluent-plugin-mysqlslowquery"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "0.0.1"
17
+ gem.add_development_dependency "fluentd"
18
+ gem.add_runtime_dependency "fluentd"
19
+ end
@@ -0,0 +1,33 @@
1
+ class MySQLSlowQueryInput < Fluent::TailInput
2
+ Fluent::Plugin.register_input('mysql_slow_query', self)
3
+
4
+ def configure_parser(conf)
5
+ @_time = Time.new.to_i
6
+ @_record = {}
7
+ end
8
+
9
+ def parse_line(line)
10
+ if line.start_with?("#")
11
+ if line[2, 5] == "Time:"
12
+ remain = line[7..-1].strip
13
+ @_time = Time.strptime(remain, '%y%m%d %H:%M:%S').to_i
14
+ elsif line[2, 10] == "User@Host:"
15
+ remain = line[12..-1].split("@").map{|s| s.strip}
16
+ @_record["user"] = remain[0]
17
+ @_record["host"] = remain[1]
18
+ elsif line[2, 11] == "Query_time:"
19
+ sl = line.split
20
+ @_record["query_time"] = sl[2].to_f
21
+ @_record["lock_time"] = sl[4].to_f
22
+ @_record["rows_sent"] = sl[6].to_i
23
+ @_record["rows_examined"] = sl[8].to_i
24
+ end
25
+ elsif not line.upcase.start_with?('USE') and not line.upcase.start_with?('SET')
26
+ @_record["sql"] = line
27
+ n_record = @_record.clone
28
+ @_record = {}
29
+ return @_time, n_record
30
+ end
31
+ return nil, nil
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mysqlslowquery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - taka84u9
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &70320037856180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70320037856180
25
+ - !ruby/object:Gem::Dependency
26
+ name: fluentd
27
+ requirement: &70320037855740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70320037855740
36
+ description: Fluent input plugin for MySQL slow query log file.
37
+ email:
38
+ - taka84u9@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - README.md
45
+ - Rakefile
46
+ - fluent-plugin-mysqlslowquery.gemspec
47
+ - lib/fluent/plugin/in_mysql_slow_query.rb
48
+ homepage: https://github.com/taka84u9/fluent-plugin-mysqlslowquery
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.10
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Fluent input plugin for MySQL slow query log file.
72
+ test_files: []