ringbarker 0.0.1 → 0.0.2

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/README.txt CHANGED
@@ -14,6 +14,7 @@ A simple parser for Rails logs.
14
14
  * Collects the fluff between Processing blocks too.
15
15
  * Does as little interpretation of the parsed requests as possible. This is left up to the client.
16
16
  * Needs better doco.
17
+ * Needs Rails 2.0 format support.
17
18
 
18
19
  == SYNOPSIS:
19
20
 
@@ -2,5 +2,5 @@ $:.unshift File.dirname(__FILE__)
2
2
  require 'ringbarker/parser'
3
3
 
4
4
  module Ringbarker
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -17,14 +17,19 @@ class Ringbarker::Entry
17
17
  attr_reader :lines
18
18
  attr_reader :controller, :action, :verb, :ip
19
19
  attr_reader :session_id, :parameters, :http_code, :complete
20
- attr_reader :fluff
20
+ attr_reader :fluff, :request_time, :requests_per_sec
21
+ attr_reader :index
22
+
23
+ @@index = 0
21
24
 
22
25
  attr_accessor :requested_at
23
26
 
24
- def initialize(lines=[],complete=false,fluff=false)
25
- @lines = lines
27
+ def initialize(lines=[],complete=false,fluff=false)
28
+ @lines = lines.dup
26
29
  @complete = complete
27
30
  @fluff = fluff
31
+
32
+ @index = (@@index += 1)
28
33
  end
29
34
 
30
35
  def self.new_from_fluff(lines,requested_at)
@@ -34,12 +39,16 @@ class Ringbarker::Entry
34
39
  end
35
40
 
36
41
  def << line
42
+ next unless line
43
+
37
44
  if @lines.empty?
38
45
  parse_header(line)
39
46
  elsif line.starts_with? 'Completed'
40
47
  parse_completed(line)
41
48
  elsif line.starts_with? 'Rendering'
42
49
  parse_rendering(line)
50
+ else
51
+ parse_details(line)
43
52
  end
44
53
 
45
54
  @lines << line
@@ -53,10 +62,14 @@ class Ringbarker::Entry
53
62
  def fluff?; @fluff; end
54
63
 
55
64
 
56
- COMPLETED_RE = /(\d+) \w+ \[http:\/\/[^\]]+\]$/
65
+ COMPLETED_RE = /Completed in ([\d\.]+) \((\d+) reqs\/sec\) | DB: ([\d\.]+) \((\d)%\) | (\d+) \w+ \[http:\/\/[^\]]+\]$/
57
66
  def parse_completed line
58
67
  if m = line.match(COMPLETED_RE)
59
- @http_code = m[1].to_i
68
+ @complete_line = line
69
+
70
+ _,@request_time,@requests_per_sec,_,_,@http_code = *m
71
+
72
+ @http_code = @http_code.to_i
60
73
  @complete = true
61
74
  end
62
75
  end
@@ -95,4 +108,9 @@ class Ringbarker::Entry
95
108
  def set_params(_,params)
96
109
  @parameters = params
97
110
  end
111
+
112
+ # Completed in 0.08129 (12 reqs/sec) | DB: 3.66793 (4512%) | 302 Found [http://shotgun.syd.rsp.com.au/]
113
+ def complete_line
114
+
115
+ end
98
116
  end
@@ -1,4 +1,5 @@
1
1
  require 'ringbarker/entry'
2
+ require 'pp'
2
3
 
3
4
  module Ringbarker
4
5
  class Parser
@@ -25,15 +26,33 @@ module Ringbarker
25
26
 
26
27
  def collect_fluff
27
28
  return if @fluff.empty?
29
+
28
30
  @entries << Entry.new_from_fluff(@fluff,@last_time)
31
+ @last_time = Time.now.to_i
32
+
29
33
  @fluff = []
30
34
  end
31
35
 
36
+ def cleanup
37
+ collect_fluff unless @current_entry
38
+ self
39
+ end
40
+
32
41
  def cleanup_dequeue
33
42
  collect_fluff unless @current_entry
34
43
  dequeue
35
44
  end
36
45
 
46
+ def dump
47
+ puts "Parser"
48
+ puts "entries: #{@entries.inspect}"
49
+ puts "fluff: #{@fluff.inspect}"
50
+ puts "last_time: #{@last_time}"
51
+
52
+ puts "current_entry: #{@current_entry.__id__}"
53
+ pp @current_entry
54
+ end
55
+
37
56
  def dequeue
38
57
  deq = if @entries.empty?
39
58
  []
@@ -90,6 +90,21 @@ describe Ringbarker::Entry, "parsing a completed line" do
90
90
  end
91
91
  end
92
92
 
93
+ describe Ringbarker::Entry, "parsing a regressed completed line" do
94
+ before do
95
+ @entry = Ringbarker::Entry.new
96
+ @entry.parse_completed "Completed in 0.00026 (3890 reqs/sec) | DB: 0.00018 (69%) | 302 Found [http://test.host/payments;eway_callback?eWAYAuthCode=123456&ewayTrxnNumber=10004&eWAYoption3=&ewayTrxnStatus=True&eWAYresponseText=Transaction+Approved%28Test+CVN+Gateway%29&eWAYresponseCode=00&eWAYReturnAmount=%2426.10&ewayTrxnReference=1011869&eWAYoption1=&eWAYoption2=]\n"
97
+ end
98
+
99
+ it "should have http code" do
100
+ @entry.http_code.should == 302
101
+ end
102
+
103
+ it "should be complete" do
104
+ @entry.should be_complete
105
+ end
106
+ end
107
+
93
108
  describe Ringbarker::Entry, "parsing a line beginning with completed" do
94
109
  before do
95
110
  @entry = Ringbarker::Entry.new
@@ -133,4 +148,6 @@ describe Ringbarker::Entry, "parsing a normal Rendered line" do
133
148
  it "should not be complete" do
134
149
  @entry.should_not be_complete
135
150
  end
136
- end
151
+ end
152
+
153
+
@@ -1,5 +1,15 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
+ module DataHelper
4
+ def datafile(file)
5
+ File.dirname(__FILE__)+'/data/'+file
6
+ end
7
+
8
+ def data(file)
9
+ File.open(datafile(file))
10
+ end
11
+ end
12
+
3
13
 
4
14
  describe Ringbarker do
5
15
  before do
@@ -109,4 +119,23 @@ describe Ringbarker, "with no entries, after dequeuing" do
109
119
  it "should have empty array of entries" do
110
120
  @parser.entries.should == []
111
121
  end
122
+ end
123
+
124
+ describe Ringbarker, "with no entries, after dequeuing" do
125
+ include DataHelper
126
+
127
+ before do
128
+ @parser = Ringbarker::Parser.new
129
+ data('snippet.txt').each do |line|
130
+ @parser << line
131
+ end
132
+
133
+ @parser.dump
134
+ @deq = @parser.dequeue
135
+ @parser.dump
136
+ end
137
+
138
+ it "should have one entry dequeued" do
139
+ @deq.should have(1).item
140
+ end
112
141
  end
metadata CHANGED
@@ -1,33 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: ringbarker
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-09-19 00:00:00 +10:00
8
- summary: simple Rails log parser
9
- require_paths:
10
- - lib
11
- email: lachie@smartbomb.com.au
12
- homepage: " by Lachie Cox"
13
- rubyforge_project: rails-oceania
14
- description: "== FEATURES/PROBLEMS: * Parses the Rails log. * Recognises Processing...Completed blocks. * Recognises Processing...exception...Rendering rescue blocks. * Collects the fluff between Processing blocks too. * Does as little interpretation of the parsed requests as possible. This is left up to the client. * Needs better doco. == SYNOPSIS: require 'rubygems' require 'ringbarker' @parser = Ringbarker::Parser.new @entries = []"
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.0.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Lachie Cox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-16 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.0
23
+ version:
24
+ description: "== FEATURES/PROBLEMS: * Parses the Rails log. * Recognises Processing...Completed blocks. * Recognises Processing...exception...Rendering rescue blocks. * Collects the fluff between Processing blocks too. * Does as little interpretation of the parsed requests as possible. This is left up to the client. * Needs better doco. * Needs Rails 2.0 format support. == SYNOPSIS: require 'rubygems' require 'ringbarker' @parser = Ringbarker::Parser.new @entries = []"
25
+ email: lachie@smartbomb.com.au
26
+ executables:
27
+ - ringbarker
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
31
34
  files:
32
35
  - History.txt
33
36
  - Manifest.txt
@@ -40,29 +43,33 @@ files:
40
43
  - spec/entry_spec.rb
41
44
  - spec/parser_spec.rb
42
45
  - spec/spec_helper.rb
43
- test_files:
44
- - spec/entry_spec.rb
45
- - spec/parser_spec.rb
46
+ has_rdoc: true
47
+ homepage: " by Lachie Cox"
48
+ post_install_message:
46
49
  rdoc_options:
47
50
  - --main
48
51
  - README.txt
49
- extra_rdoc_files:
50
- - History.txt
51
- - Manifest.txt
52
- - README.txt
53
- executables:
54
- - ringbarker
55
- extensions: []
56
-
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
57
66
  requirements: []
58
67
 
59
- dependencies:
60
- - !ruby/object:Gem::Dependency
61
- name: hoe
62
- version_requirement:
63
- version_requirements: !ruby/object:Gem::Version::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 1.3.0
68
- version:
68
+ rubyforge_project: rails-oceania
69
+ rubygems_version: 1.0.1
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: simple Rails log parser
73
+ test_files:
74
+ - spec/entry_spec.rb
75
+ - spec/parser_spec.rb