myslog 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +21 -17
  2. data/lib/myslog.rb +7 -2
  3. data/myslog.gemspec +1 -1
  4. metadata +10 -5
data/README.md CHANGED
@@ -16,25 +16,29 @@ Usage
16
16
  ```ruby
17
17
  myslog = MySlog.new
18
18
 
19
- f = open("mysql-slow-query.log")
20
- lines = f.read.split("\n")
21
- f.close
22
-
23
- logs = myslog.parse(lines)
19
+ text = <<-EOF
20
+ # Time: 111003 14:17:38
21
+ # User@Host: root[root] @ localhost []
22
+ # Query_time: 0.000270 Lock_time: 0.000097 Rows_sent: 1 Rows_examined: 0
23
+ SET timestamp=1317619058;
24
+ SELECT * FROM life;
25
+ EOF
26
+
27
+ records = myslog.parse(text)
24
28
  ```
25
29
 
26
- `logs` is Array of Hash
30
+ `records` is Array of Hash
27
31
 
28
32
  ```ruby
29
- log = logs.first
30
-
31
- log[:date]
32
- log[:user]
33
- log[:host]
34
- log[:host_ip]
35
- log[:query_time]
36
- log[:lock_time]
37
- log[:rows_sent]
38
- log[:rows_examined]
39
- log[:sql]
33
+ record = records.first
34
+
35
+ record[:time] #=> Time(20111003 14:17:38)
36
+ record[:user] #=> "root[root]"
37
+ record[:host] #=> "localhost"
38
+ record[:host_ip] #=> ""
39
+ record[:query_time] #=> 0.000270
40
+ record[:lock_time] #=> 0.000097
41
+ record[:rows_sent] #=> 1
42
+ record[:rows_examined] #=> 0
43
+ record[:sql] #=> "SET timestamp=1317619058; SELECT * FROM life;"
40
44
  ```
data/lib/myslog.rb CHANGED
@@ -66,8 +66,13 @@ class MySlog
66
66
 
67
67
  elems = record.split(" ")
68
68
  response[:user] = elems[2].strip
69
- response[:host] = elems[4].strip
70
- response[:host_ip] = elems[5].strip[1...-1]
69
+ if elems[5] == nil
70
+ response[:host] = nil
71
+ response[:host_ip] = elems[4].strip[1...-1]
72
+ else
73
+ response[:host] = elems[4].strip
74
+ response[:host_ip] = elems[5].strip[1...-1]
75
+ end
71
76
 
72
77
  record = records.shift
73
78
  elems = record.split(" ")
data/myslog.gemspec CHANGED
@@ -12,6 +12,6 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "myslog"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.0.4"
15
+ gem.version = "0.0.5"
16
16
  gem.add_development_dependency "rspec"
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-07 00:00:00.000000000Z
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70181126520020 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70181126520020
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: MySQL slow query parser.
26
31
  email:
27
32
  - taka84u9@gmail.com
@@ -58,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
63
  version: '0'
59
64
  requirements: []
60
65
  rubyforge_project:
61
- rubygems_version: 1.8.10
66
+ rubygems_version: 1.8.23
62
67
  signing_key:
63
68
  specification_version: 3
64
69
  summary: MySQL slow query parser.