mysql-slowquery-parser 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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +97 -0
- data/Rakefile +5 -0
- data/lib/mysql-slowquery-parser.rb +105 -0
- data/mysql-slowquery-parser.gemspec +22 -0
- data/spec/mysql-slowquery-parser_spec.rb +180 -0
- data/spec/spec_helper.rb +2 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d096ce5af2a5cb05012ae9b545719e9a098af76
|
4
|
+
data.tar.gz: 9f4eca541514eb6a18fbc9794d4a059efbd82cd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6ba236c879e18463882d13532a86d642ebb42aef49127eab714cd63028dad62e2e31ed3ac1e9f94a0fcda54f0a9ce0788413d6eee4a48b16a1e6e5b7edc7e5b
|
7
|
+
data.tar.gz: c33841ebd5c0c922dd79535b95df70c7952ea04d5b075b2bac1cd63bc82d5874af14874641da51bb28f80162d3f7169236d1161f56829da075ffaf527b35b48e
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 studio3104
|
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,97 @@
|
|
1
|
+
# MySQLSlowQueryParser [](https://travis-ci.org/studio3104/mysql-slowquery-parser)
|
2
|
+
|
3
|
+
Slow query log parser for MySQL
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mysql-slowquery-parser'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mysql-slowquery-parser
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
slowquery = <<SLOW
|
23
|
+
/usr/local/Cellar/mysql/5.6.12/bin/mysqld, Version: 5.6.12 (Source distribution). started with:
|
24
|
+
Tcp port: 3306 Unix socket: /tmp/mysql.sock
|
25
|
+
Time Id Command Argument
|
26
|
+
# Time: 140128 13:39:11
|
27
|
+
# User@Host: [user] @ localhost [] Id: 8
|
28
|
+
# Query_time: 2.001227 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
|
29
|
+
SET timestamp=1390883951;
|
30
|
+
SELECT
|
31
|
+
*
|
32
|
+
FROM
|
33
|
+
mysql.user;
|
34
|
+
/usr/local/Cellar/mysql/5.6.12/bin/mysqld, Version: 5.6.12 (Source distribution). started with:
|
35
|
+
Tcp port: 3306 Unix socket: /tmp/mysql.sock
|
36
|
+
Time Id Command Argument
|
37
|
+
# Time: 140326 0:36:56
|
38
|
+
# User@Host: root[root] @ localhost [] Id: 51
|
39
|
+
# Query_time: 10.001140 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
|
40
|
+
SET timestamp=1395761816;
|
41
|
+
select sleep(10);
|
42
|
+
# Time: 140326 0:37:11
|
43
|
+
# User@Host: root[root] @ localhost [] Id: 51
|
44
|
+
# Query_time: 10.001114 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
|
45
|
+
use mysql;
|
46
|
+
SET timestamp=1395761831;
|
47
|
+
select sleep(10);
|
48
|
+
SLOW
|
49
|
+
```
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
MySQLSlowQueryParser.parse(slowquery)
|
53
|
+
```
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
[
|
57
|
+
{
|
58
|
+
datetime: 1390883951,
|
59
|
+
user: 'user',
|
60
|
+
host: 'localhost',
|
61
|
+
query_time: 2.001227,
|
62
|
+
lock_time: 0.0,
|
63
|
+
rows_sent: 1,
|
64
|
+
rows_examined: 0,
|
65
|
+
sql: 'SELECT\n *\nFROM\n mysql.user'
|
66
|
+
},
|
67
|
+
{
|
68
|
+
datetime: 1395761816,
|
69
|
+
user: 'root',
|
70
|
+
host: 'localhost',
|
71
|
+
query_time: 10.00114,
|
72
|
+
lock_time: 0.0,
|
73
|
+
rows_sent: 1,
|
74
|
+
rows_examined: 0,
|
75
|
+
sql: 'select sleep(10)'
|
76
|
+
},
|
77
|
+
{
|
78
|
+
datetime: 1395761831,
|
79
|
+
user: 'root',
|
80
|
+
host: 'localhost',
|
81
|
+
query_time: 10.001114,
|
82
|
+
lock_time: 0.0,
|
83
|
+
rows_sent: 1,
|
84
|
+
rows_examined: 0,
|
85
|
+
db: 'mysql',
|
86
|
+
sql: 'select sleep(10)'
|
87
|
+
}
|
88
|
+
]
|
89
|
+
```
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
1. Fork it ( https://github.com/studio3104/mysql-slowquery-parser/fork )
|
94
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
95
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
96
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
97
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
class MySQLSlowQueryParser
|
4
|
+
def self.parse(raw_slow_logs)
|
5
|
+
split_raw_slow_logs(raw_slow_logs).map { |raw_slow_log|
|
6
|
+
parse_slow_log(raw_slow_log)
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
# 生スローログを意味のある単位に分割
|
11
|
+
def self.split_raw_slow_logs(raw_slow_logs)
|
12
|
+
result = []
|
13
|
+
part = []
|
14
|
+
|
15
|
+
raw_slow_logs.each_line do |line|
|
16
|
+
part << line
|
17
|
+
if line.end_with?(';', ";\n") && !line.start_with?('use ', 'SET timestamp=')
|
18
|
+
result << part
|
19
|
+
part = []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse_slow_log(raw_slow_log)
|
27
|
+
result = {}
|
28
|
+
line = raw_slow_log.shift
|
29
|
+
|
30
|
+
while !line.start_with?('#')
|
31
|
+
# こういうのを suppress する
|
32
|
+
#### /usr/local/Cellar/mysql/5.6.12/bin/mysqld, Version: 5.6.12 (Source distribution). started with:
|
33
|
+
#### Tcp port: 3306 Unix socket: /tmp/mysql.sock
|
34
|
+
line = raw_slow_log.shift
|
35
|
+
end
|
36
|
+
|
37
|
+
if record = line.match(/^# Time:\s+(.+)/)
|
38
|
+
result[:datetime] = Time.parse(record[1]).to_i
|
39
|
+
line = raw_slow_log.shift
|
40
|
+
end
|
41
|
+
|
42
|
+
if record = line.match(/^# User@Host: ([^\[]+)?\[([^\]]*)\] @ ([^\[]+)\[([^\]]*)\]/)
|
43
|
+
result[:user] = record[1].nil? || record[1].empty? ? record[2] : record[1]
|
44
|
+
result[:host] = record[3].nil? || record[3].strip.empty? ? record[4] : record[3].strip
|
45
|
+
line = raw_slow_log.shift
|
46
|
+
end
|
47
|
+
|
48
|
+
# こういうのをハッシュにする
|
49
|
+
#### # Query_time: 4.267253 Lock_time: 0.000017 Rows_sent: 0 Rows_examined: 734266 Rows_affected: 734266 Rows_read: 734266
|
50
|
+
while line.start_with?('#')
|
51
|
+
line = line.sub(/^#\s+/, '')
|
52
|
+
|
53
|
+
# ' ' で split したかったけど、' ' で区切られてる場合(MacのMySQLで確認)もあったからこうした
|
54
|
+
record = line.split(/\s+/).map { |val|
|
55
|
+
case val
|
56
|
+
when /\:$/
|
57
|
+
val.sub(/\:$/, '').downcase.to_sym
|
58
|
+
when /^\d+$/
|
59
|
+
val.to_i
|
60
|
+
when /^\d+\.\d+$/
|
61
|
+
val.to_f
|
62
|
+
else
|
63
|
+
val
|
64
|
+
end
|
65
|
+
}
|
66
|
+
|
67
|
+
# # Thread_id: 45 Schema: Last_errno: 0 Killed: 0
|
68
|
+
# ↑ の Schema みたいに、値がない場合に nil を埋めて対応する
|
69
|
+
begin
|
70
|
+
result = result.merge(Hash[*record])
|
71
|
+
rescue ArgumentError # odd number of arguments for Hash
|
72
|
+
_record = []
|
73
|
+
record.each_with_index do |val, i|
|
74
|
+
_record << val
|
75
|
+
if val.is_a?(Symbol) && record[i+1].is_a?(Symbol)
|
76
|
+
_record << nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
_record << nil if _record.last.is_a?(Symbol)
|
80
|
+
result = result.merge(Hash[*_record])
|
81
|
+
end
|
82
|
+
|
83
|
+
line = raw_slow_log.shift
|
84
|
+
end
|
85
|
+
|
86
|
+
if record = line.match(/^use (\w+);$/)
|
87
|
+
result[:db] = record[1]
|
88
|
+
line = raw_slow_log.shift
|
89
|
+
end
|
90
|
+
|
91
|
+
if record = line.match(/^SET timestamp=(\d+);$/)
|
92
|
+
result[:datetime] = record[1].to_i
|
93
|
+
line = raw_slow_log.shift
|
94
|
+
end
|
95
|
+
|
96
|
+
result[:sql] = line
|
97
|
+
raw_slow_log.each do |l|
|
98
|
+
result[:sql] = result[:sql] + l
|
99
|
+
end
|
100
|
+
result[:sql] = result[:sql].sub(/;$/, '')
|
101
|
+
result[:sql] = result[:sql].strip
|
102
|
+
|
103
|
+
result
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: 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 |spec|
|
6
|
+
spec.name = 'mysql-slowquery-parser'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ["studio3104"]
|
9
|
+
spec.email = ["studio3104.com@gmail.com"]
|
10
|
+
spec.summary = %q{MySQL slow query log parser}
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/studio3104/mysql-slowquery-parser'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mysql-slowquery-parser'
|
3
|
+
|
4
|
+
describe MySQLSlowQueryParser do
|
5
|
+
let(:parser) { MySQLSlowQueryParser }
|
6
|
+
let(:mysql_raw_slow_logs) {
|
7
|
+
<<-EOF
|
8
|
+
/usr/local/Cellar/mysql/5.6.12/bin/mysqld, Version: 5.6.12 (Source distribution). started with:
|
9
|
+
Tcp port: 3306 Unix socket: /tmp/mysql.sock
|
10
|
+
Time Id Command Argument
|
11
|
+
# Time: 140128 13:39:11
|
12
|
+
# User@Host: [user] @ localhost [] Id: 8
|
13
|
+
# Query_time: 2.001227 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
|
14
|
+
SET timestamp=1390883951;
|
15
|
+
select sleep(2);
|
16
|
+
/usr/local/Cellar/mysql/5.6.12/bin/mysqld, Version: 5.6.12 (Source distribution). started with:
|
17
|
+
Tcp port: 3306 Unix socket: /tmp/mysql.sock
|
18
|
+
Time Id Command Argument
|
19
|
+
# Time: 140326 0:36:56
|
20
|
+
# User@Host: root[root] @ localhost [] Id: 51
|
21
|
+
# Query_time: 10.001140 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
|
22
|
+
SET timestamp=1395761816;
|
23
|
+
select sleep(10);
|
24
|
+
# Time: 140326 0:37:11
|
25
|
+
# User@Host: root[root] @ localhost [] Id: 51
|
26
|
+
# Query_time: 10.001114 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
|
27
|
+
use mysql;
|
28
|
+
SET timestamp=1395761831;
|
29
|
+
select sleep(10);
|
30
|
+
EOF
|
31
|
+
}
|
32
|
+
let(:percona_raw_slow_logs) {
|
33
|
+
<<-EOF
|
34
|
+
# Time: 120913 12:58:21
|
35
|
+
# User@Host: root[root] @ localhost []
|
36
|
+
# Thread_id: 45 Schema: sbtest Last_errno: 0 Killed: 0
|
37
|
+
# Query_time: 34.452360 Lock_time: 0.000134 Rows_sent: 50 Rows_examined: 8800050 Rows_affected: 0 Rows_read: 50
|
38
|
+
# Bytes_sent: 3499 Tmp_tables: 1 Tmp_disk_tables: 1 Tmp_table_sizes: 2450800000
|
39
|
+
# InnoDB_trx_id: B08
|
40
|
+
# QC_Hit: No Full_scan: Yes Full_join: No Tmp_table: Yes Tmp_table_on_disk: Yes
|
41
|
+
# Filesort: Yes Filesort_on_disk: Yes Merge_passes: 202
|
42
|
+
# InnoDB_IO_r_ops: 58994 InnoDB_IO_r_bytes: 966557696 InnoDB_IO_r_wait: 8.327283
|
43
|
+
# InnoDB_rec_lock_wait: 0.000000 InnoDB_queue_wait: 0.000000
|
44
|
+
# InnoDB_pages_distinct: 60281
|
45
|
+
SET timestamp=1347508701;
|
46
|
+
SELECT * FROM sbtest ORDER BY RAND() LIMIT 50;
|
47
|
+
/usr/sbin/mysqld, Version: 5.5.34-32.0-log (Percona Server (GPL), Release rel32.0, Revision 591). started with:
|
48
|
+
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
|
49
|
+
Time Id Command Argument
|
50
|
+
# Time: 131226 19:07:02
|
51
|
+
# User@Host: user[user] @ [192.168.10.11]
|
52
|
+
# Thread_id: 9510259 Schema: sbtest Last_errno: 0 Killed: 0
|
53
|
+
# Query_time: 4.901885 Lock_time: 0.000065 Rows_sent: 8309 Rows_examined: 69763781 Rows_affected: 0 Rows_read: 69763781
|
54
|
+
# Bytes_sent: 802732
|
55
|
+
SET timestamp=1388052422;
|
56
|
+
SELECT
|
57
|
+
*
|
58
|
+
FROM
|
59
|
+
sbtest;
|
60
|
+
EOF
|
61
|
+
}
|
62
|
+
|
63
|
+
let(:percona_raw_slow_logs_without_Schema) {
|
64
|
+
<<-EOF
|
65
|
+
# Time: 120913 12:58:21
|
66
|
+
# User@Host: root[root] @ localhost []
|
67
|
+
# Thread_id: 45 Schema: Last_errno: 0 Killed: 0
|
68
|
+
# Query_time: 34.452360 Lock_time: 0.000134 Rows_sent: 50 Rows_examined: 8800050 Rows_affected: 0 Rows_read: 50
|
69
|
+
# Bytes_sent: 3499 Tmp_tables: 1 Tmp_disk_tables: 1 Tmp_table_sizes: 2450800000
|
70
|
+
# InnoDB_trx_id: B08
|
71
|
+
# QC_Hit: No Full_scan: Yes Full_join: No Tmp_table: Yes Tmp_table_on_disk: Yes
|
72
|
+
# Filesort: Yes Filesort_on_disk: Yes Merge_passes: 202
|
73
|
+
# InnoDB_IO_r_ops: 58994 InnoDB_IO_r_bytes: 966557696 InnoDB_IO_r_wait: 8.327283
|
74
|
+
# InnoDB_rec_lock_wait: 0.000000 InnoDB_queue_wait: 0.000000
|
75
|
+
# InnoDB_pages_distinct: 60281
|
76
|
+
SET timestamp=1347508701;
|
77
|
+
SELECT * FROM sbtest ORDER BY RAND() LIMIT 50;
|
78
|
+
EOF
|
79
|
+
}
|
80
|
+
|
81
|
+
describe '#split_raw_slow_logs' do
|
82
|
+
context 'MySQL' do
|
83
|
+
let(:split_log) { parser.split_raw_slow_logs(mysql_raw_slow_logs) }
|
84
|
+
it { expect(split_log.size).to eq(3) }
|
85
|
+
end
|
86
|
+
context 'Percona' do
|
87
|
+
let(:split_log) { parser.split_raw_slow_logs(percona_raw_slow_logs) }
|
88
|
+
it { expect(split_log.size).to eq(2) }
|
89
|
+
end
|
90
|
+
context 'Percona without Schema' do
|
91
|
+
let(:split_log_without_Schema) { parser.split_raw_slow_logs(percona_raw_slow_logs_without_Schema) }
|
92
|
+
it { expect(split_log_without_Schema.size).to eq(1) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#parse_slow_log' do
|
97
|
+
context 'MySQL' do
|
98
|
+
let(:split_log) { parser.split_raw_slow_logs(mysql_raw_slow_logs) }
|
99
|
+
let(:parsed_logs) { split_log.map { |l| parser.parse_slow_log(l) } }
|
100
|
+
|
101
|
+
it { expect(parsed_logs.size).to eq(3) }
|
102
|
+
it do
|
103
|
+
expect(parsed_logs).to eq([
|
104
|
+
{
|
105
|
+
datetime: 1390883951, user: 'user', host: 'localhost',
|
106
|
+
query_time: 2.001227, lock_time: 0.0, rows_sent: 1, rows_examined:0,
|
107
|
+
sql: 'select sleep(2)'
|
108
|
+
},
|
109
|
+
{
|
110
|
+
datetime: 1395761816, user: 'root', host: 'localhost',
|
111
|
+
query_time: 10.00114, lock_time: 0.0, rows_sent: 1, rows_examined: 0,
|
112
|
+
sql: 'select sleep(10)'
|
113
|
+
},
|
114
|
+
{
|
115
|
+
datetime: 1395761831, user: 'root', host: 'localhost',
|
116
|
+
query_time: 10.001114, lock_time: 0.0, rows_sent: 1, rows_examined: 0,
|
117
|
+
db: 'mysql', sql: 'select sleep(10)'
|
118
|
+
}
|
119
|
+
])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'Percona' do
|
124
|
+
let(:split_log) { parser.split_raw_slow_logs(percona_raw_slow_logs) }
|
125
|
+
let(:parsed_logs) { split_log.map { |l| parser.parse_slow_log(l) } }
|
126
|
+
|
127
|
+
it { expect(parsed_logs.size).to eq(2) }
|
128
|
+
it do
|
129
|
+
expect(parsed_logs).to eq([
|
130
|
+
{
|
131
|
+
datetime: 1347508701, user: 'root', host: 'localhost',
|
132
|
+
thread_id: 45, schema: 'sbtest', last_errno: 0, killed: 0,
|
133
|
+
query_time: 34.45236, lock_time: 0.000134, rows_sent: 50, rows_examined: 8800050, rows_affected: 0, rows_read: 50,
|
134
|
+
bytes_sent: 3499, tmp_tables: 1, tmp_disk_tables: 1, tmp_table_sizes: 2450800000,
|
135
|
+
innodb_trx_id: 'B08',
|
136
|
+
qc_hit: 'No',
|
137
|
+
full_scan: 'Yes', full_join: 'No', tmp_table: 'Yes', tmp_table_on_disk: 'Yes',
|
138
|
+
filesort: 'Yes', filesort_on_disk: 'Yes', merge_passes: 202,
|
139
|
+
innodb_io_r_ops: 58994, innodb_io_r_bytes: 966557696, innodb_io_r_wait: 8.327283,
|
140
|
+
innodb_rec_lock_wait: 0.0, innodb_queue_wait: 0.0,
|
141
|
+
innodb_pages_distinct: 60281,
|
142
|
+
sql: 'SELECT * FROM sbtest ORDER BY RAND() LIMIT 50'
|
143
|
+
},
|
144
|
+
{
|
145
|
+
datetime: 1388052422, user: 'user', host: '192.168.10.11',
|
146
|
+
thread_id: 9510259, schema: 'sbtest', last_errno: 0, killed: 0,
|
147
|
+
query_time: 4.901885, lock_time: 6.5e-05, rows_sent: 8309, rows_examined: 69763781, rows_affected: 0, rows_read: 69763781,
|
148
|
+
bytes_sent: 802732,
|
149
|
+
sql: "SELECT\n *\nFROM\n sbtest"
|
150
|
+
}
|
151
|
+
])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'Percona without Schema' do
|
156
|
+
let(:split_log_without_Schema) { parser.split_raw_slow_logs(percona_raw_slow_logs_without_Schema) }
|
157
|
+
let(:parsed_logs_without_Schema) { split_log_without_Schema.map { |l| parser.parse_slow_log(l) } }
|
158
|
+
|
159
|
+
it { expect(parsed_logs_without_Schema.size).to eq(1) }
|
160
|
+
it do
|
161
|
+
expect(parsed_logs_without_Schema).to eq([
|
162
|
+
{
|
163
|
+
datetime: 1347508701, user: 'root', host: 'localhost',
|
164
|
+
thread_id: 45, schema: nil, last_errno: 0, killed: 0,
|
165
|
+
query_time: 34.45236, lock_time: 0.000134, rows_sent: 50, rows_examined: 8800050, rows_affected: 0, rows_read: 50,
|
166
|
+
bytes_sent: 3499, tmp_tables: 1, tmp_disk_tables: 1, tmp_table_sizes: 2450800000,
|
167
|
+
innodb_trx_id: 'B08',
|
168
|
+
qc_hit: 'No',
|
169
|
+
full_scan: 'Yes', full_join: 'No', tmp_table: 'Yes', tmp_table_on_disk: 'Yes',
|
170
|
+
filesort: 'Yes', filesort_on_disk: 'Yes', merge_passes: 202,
|
171
|
+
innodb_io_r_ops: 58994, innodb_io_r_bytes: 966557696, innodb_io_r_wait: 8.327283,
|
172
|
+
innodb_rec_lock_wait: 0.0, innodb_queue_wait: 0.0,
|
173
|
+
innodb_pages_distinct: 60281,
|
174
|
+
sql: 'SELECT * FROM sbtest ORDER BY RAND() LIMIT 50'
|
175
|
+
},
|
176
|
+
])
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql-slowquery-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- studio3104
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: MySQL slow query log parser
|
42
|
+
email:
|
43
|
+
- studio3104.com@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/mysql-slowquery-parser.rb
|
55
|
+
- mysql-slowquery-parser.gemspec
|
56
|
+
- spec/mysql-slowquery-parser_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
homepage: https://github.com/studio3104/mysql-slowquery-parser
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: MySQL slow query log parser
|
82
|
+
test_files:
|
83
|
+
- spec/mysql-slowquery-parser_spec.rb
|
84
|
+
- spec/spec_helper.rb
|