myslog 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01ae65979b5ba26faf80d43e15c9a0f8178e0f61
4
- data.tar.gz: 8e4c38a14bf1fdd953ee165423e5fea39395fed0
3
+ metadata.gz: acc2b4218401ea178a7879e7af86a35cb421833f
4
+ data.tar.gz: 3fd0187e5be618194825df871deab6b7b2e6429b
5
5
  SHA512:
6
- metadata.gz: 781f661946cde324e8ae78e5ee30aaed434478d07344b3abe699fc6993d5b18e1d93e1685b88f0026c0e3be97438bddb063c8562361474c2e4b048b2d330e4aa
7
- data.tar.gz: 8d4965c1611b43bbc04a1d911da3d0e2ae6a978bf621e80c057cd2add85ebd0b9ba00693071c452ef8919a94537e8505a61ffb728a00749f097831c3b6f68c62
6
+ metadata.gz: 0b0b5b8e7db1e435d4d22a033deb05f6bba7a9cea5657d1e77959df88dccea4e273f7b26eacb5cc7fc91b0f190ce696d0c7826973501428431609a057a6cbca6
7
+ data.tar.gz: 47b2f84d9b281e5f8df98cf65767e076ce5058a54af25c8ca2b0cabcea0882c3027efaddcb3cb6ef9f865ad589f247c9c5607196c1369e20bc87445f90064ff3
@@ -38,15 +38,10 @@ class MySlog
38
38
 
39
39
  if record.start_with? "# User@Host:"
40
40
 
41
- elems = record.split(" ")
42
- response[:user] = elems[2].strip
43
- if elems[5] == nil
44
- response[:host] = nil
45
- response[:host_ip] = elems[4].strip[1...-1]
46
- else
47
- response[:host] = elems[4].strip
48
- response[:host_ip] = elems[5].strip[1...-1]
49
- end
41
+ elems = record.split(/ /, 7)
42
+ response[:user] = elems[2].strip
43
+ response[:host] = elems[4].empty? ? nil : elems[4].strip
44
+ response[:host_ip] = elems[5].strip[1...-1]
50
45
  elsif record.start_with? "#"
51
46
 
52
47
  elems = record[2..-1].strip().split " "
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "myslog"
3
- spec.version = "0.1.0"
4
- spec.authors = ["taka84u9"]
3
+ spec.version = "0.1.1"
4
+ spec.authors = ["Yuku Takahashi"]
5
5
  spec.email = ["taka84u9@gmail.com"]
6
6
  spec.summary = "MySQL slow query parser."
7
7
  spec.description = "MySQL slow query parser."
@@ -53,6 +53,12 @@ use mysql;
53
53
  SET timestamp=1455094936;
54
54
  select
55
55
  sleep(2);
56
+ # Time: 160219 21:58:25
57
+ # User@Host: root[root] @ [192.168.10.1] Id: 1
58
+ # Query_time: 0.000985 Lock_time: 0.000985 Rows_sent: 1 Rows_examined: 1
59
+ use test_db;
60
+ SET timestamp=1455886705;
61
+ select * from test_table;
56
62
  EOF
57
63
  end
58
64
 
@@ -121,7 +127,13 @@ sleep(2);
121
127
  expect(record[0]).to eq(
122
128
  "# Time: 2016-02-10T18:02:16.411200+09:00"
123
129
  )
124
-
130
+
131
+ record = results[6]
132
+ expect(record.size).to eq(4)
133
+ expect(record[0]).to eq(
134
+ "# Time: 160219 21:58:25"
135
+ )
136
+
125
137
  end
126
138
  end
127
139
 
@@ -277,7 +289,40 @@ sleep(2);
277
289
  expect(@response[:sql]).to eq(@sql.strip)
278
290
  end
279
291
  end
292
+ end
280
293
 
294
+ context "given unexist localhost and exist Id" do
295
+ describe "response" do
296
+ before :each do
297
+ @user = "root[root]"
298
+ @host = nil
299
+ @host_ip = "192.168.10.1"
300
+ @query_time = 0.000985
301
+ @lock_time = 0.000985
302
+ @rows_sent = 1
303
+ @rows_examined = 1
304
+ @sql = "SET timestamp=1455886705; SELECT * FROM test_table;"
305
+ @lines = [
306
+ "# User@Host: #{@user} @ #{@host} [#{@host_ip}] Id: 1",
307
+ "# Query_time: #{@query_time} Lock_time: #{@lock_time} Rows_sent: #{@rows_sent} Rows_examined: #{@rows_examined}",
308
+ @sql
309
+ ]
310
+ @response = @myslog.parse_record(@lines)
311
+ end
312
+
313
+ it "should have expected values" do
314
+ expect(@response[:date].utc.to_s).to eq("2016-02-19 12:58:25 UTC")
315
+ expect(@response[:user]).to eq(@user)
316
+ expect(@response[:host]).to eq(@host)
317
+ expect(@response[:host_ip]).to eq(@host_ip)
318
+ expect(@response[:query_time]).to eq(@query_time)
319
+ expect(@response[:lock_time]).to eq(@lock_time)
320
+ expect(@response[:rows_sent]).to eq(@rows_sent)
321
+ expect(@response[:rows_examined]).to eq(@rows_examined)
322
+ expect(@response[:sql]).to eq(@sql.strip)
323
+ end
324
+ end
281
325
  end
326
+
282
327
  end
283
328
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - taka84u9
7
+ - Yuku Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler