beaver 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ Beaver is a light DSL and command line utility for parsing HTTP and Rails produc
8
8
  * Did anyone submit a form with the words "kill them all"? Yikes.
9
9
  * Rails 3.2 tagged logging is cool, but what's a good way to review them?
10
10
 
11
- Read the full documentation at {jordanhollinger.com/docs/beaver/}[http://jordanhollinger.com/docs/beaver/].
12
11
  For a full list of matchers available to "hit", see the Beaver::Dam class.
13
12
  For a full list of methods available inside a "hit" block, or to members of the "hits" array in a "dam" block, see the Beaver::Request, Beaver::Parsers::Rails, and Beaver::Parsers::HTTP classes.
14
13
 
@@ -55,6 +54,15 @@ Run ''beaver'' from the command line, passing in your beaver file and some logs:
55
54
  require 'rubygems'
56
55
  require 'beaver'
57
56
 
57
+ Beaver.stream '/path/to/httpd/access_logs*' do
58
+ hit :failed_logins, :method => :post, :path => '/login', :status => 401
59
+ dam :failed_logins do
60
+ puts "#{hits.size} failed logins!"
61
+ end
62
+ end
63
+
64
+ Or with even less DSL...
65
+
58
66
  beaver = Beaver.new('/path/to/httpd/access_logs*')
59
67
  beaver.hit :failed_logins, :method => :post, :path => '/login', :status => 401
60
68
  beaver.dam :failed_logins do
@@ -62,6 +70,14 @@ Run ''beaver'' from the command line, passing in your beaver file and some logs:
62
70
  end
63
71
  beaver.stream
64
72
 
73
+ Or just to parse and return the matching requests...
74
+
75
+ requests = Beaver.dam('/path/to/rails/production.log*', :method => :put)
76
+
77
+ Or as just a parser (no filtering)...
78
+
79
+ requests = Beaver.parse('/path/to/rails/production.log*')
80
+
65
81
  == Use beaver as part of the *nix toolchain
66
82
 
67
83
  It's difficult to grep through a multi-line log format like Rails' and output each matching multi-line event (though I hear Google is working on a 'Context-Free Grep', which may help solve that). Until then, for Rails anyway, beaver is happy to step in.
@@ -1,7 +1,17 @@
1
- # Not specifically a performance analyzer (like https://github.com/wvanbergen/request-log-analyzer/wiki)
2
- # Rather, a DSL for finding out how people are using your Rails app (which could include performance).
1
+ # A DSL and library for finding out how people are using your Rails app.
3
2
  # Can also be used to parse/analyze HTTP access logs (Apache, Nginx, etc.)
3
+ #
4
+ # # Parse and return the requests
5
+ # requests = Beaver.parse('/path/to/log/files')
6
+ #
7
+ # # Parse, filters, and returns the requests (all requests are always returned)
8
+ # requests = Beaver.filter('/path/to/log/files') do
9
+ # hit :error, :status => (400..505) do
10
+ # puts "#{status} on #{path} at #{time} from #{ip} with #{params_str}"
11
+ # end
12
+ # end
4
13
  #
14
+ # # Parse and filters the requests, returns nil
5
15
  # Beaver.stream('/path/to/log/files') do
6
16
  # hit :error, :status => (400..505) do
7
17
  # puts "#{status} on #{path} at #{time} from #{ip} with #{params_str}"
@@ -9,18 +19,33 @@
9
19
  # end
10
20
  #
11
21
  module Beaver
12
- # Creates a new Beaver and immediately filters the log files. This should scale well
13
- # for even very large logs, at least when compared to Beaver#parse.
22
+ # Parses the logs and returns the requests.
23
+ def self.parse(*args)
24
+ Beaver.new(*args).parse.requests
25
+ end
26
+
27
+ # Parses the logs and filters them through the given block. *All* parsed requests
28
+ # are returned, not just the ones that matched. This is useful for when you take your action(s) on the matching reqeusts *inside* the block, but you still want access to all the requsts afterwords.
29
+ def self.filter(*args, &blk)
30
+ Beaver.new(*args, &blk).parse.filter.requests
31
+ end
32
+
33
+ # Parses the logs and filters them through the (optional) block. Parsed requests are
34
+ # not retained, hence are not returned. Returns nil.
35
+ #
36
+ # In theory, this should be more memory efficient than Beaver#filter.
14
37
  def self.stream(*args, &blk)
15
- raise ArgumentError, 'You must pass a block to Beaver#stream' unless block_given?
16
38
  Beaver.new(*args, &blk).stream
39
+ nil
17
40
  end
18
41
 
19
- # Identical to Beaver#stream, except that the requests are retained, so you may
20
- # examine them afterwards. For large logs, this may be noticibly inefficient.
21
- def self.parse(*args, &blk)
22
- raise ArgumentError, 'You must pass a block to Beaver#parse' unless block_given?
23
- Beaver.new(*args, &blk).parse.filter
42
+ # Parses the logs and filters them through the provided matcher options. Returns *only* the matching requests.
43
+ def self.dam(*args)
44
+ beaver = Beaver.new(*args)
45
+ dam = beaver.hit :hits
46
+ beaver.parse
47
+ beaver.filter
48
+ dam.hits
24
49
  end
25
50
 
26
51
  # Alias to Beaver::Beaver.new
@@ -84,7 +109,7 @@ module Beaver
84
109
  end
85
110
 
86
111
  # Parses the logs and immediately filters them through the dams. Requests are not retained,
87
- # so this should scale well to very large sets of logs.
112
+ # so this should scale better to very large sets of logs.
88
113
  def stream
89
114
  # Match the request against each dam, and run the dam's callback
90
115
  _parse do |request|
@@ -1,4 +1,4 @@
1
1
  module Beaver
2
- MAJOR_VERSION, MINOR_VERSION, TINY_VERSION, PRE_VERSION = 1, 3, 1, nil # :nodoc:
2
+ MAJOR_VERSION, MINOR_VERSION, TINY_VERSION, PRE_VERSION = 1, 4, 0, nil # :nodoc:
3
3
  VERSION = [MAJOR_VERSION, MINOR_VERSION, TINY_VERSION, PRE_VERSION].compact.join '.' # :nodoc:
4
4
  end
metadata CHANGED
@@ -1,32 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: beaver
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 3
8
- - 1
9
- version: 1.3.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Jordan Hollinger
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-06-30 00:00:00 -04:00
18
- default_executable:
12
+ date: 2012-11-12 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
- description: A simple DSL and command-line tool for discovering what people are up to in your Rails app
14
+ description: A simple DSL and command-line tool for discovering what people are up
15
+ to in your Rails app
22
16
  email: jordan@jordanhollinger.com
23
- executables:
17
+ executables:
24
18
  - beaver
25
19
  extensions: []
26
-
27
20
  extra_rdoc_files: []
28
-
29
- files:
21
+ files:
30
22
  - lib/beaver.rb
31
23
  - lib/beaver/dam.rb
32
24
  - lib/beaver/beaver.rb
@@ -38,37 +30,28 @@ files:
38
30
  - README.rdoc
39
31
  - LICENSE
40
32
  - bin/beaver
41
- has_rdoc: true
42
33
  homepage: http://github.com/jhollinger/beaver
43
34
  licenses: []
44
-
45
35
  post_install_message:
46
36
  rdoc_options: []
47
-
48
- require_paths:
37
+ require_paths:
49
38
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
39
+ required_ruby_version: !ruby/object:Gem::Requirement
51
40
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
58
- required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
46
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- segments:
64
- - 0
65
- version: "0"
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
66
51
  requirements: []
67
-
68
52
  rubyforge_project:
69
- rubygems_version: 1.3.7
53
+ rubygems_version: 1.8.23
70
54
  signing_key:
71
55
  specification_version: 3
72
56
  summary: Rails log parser
73
57
  test_files: []
74
-