Module: Beaver

Defined in:
lib/beaver/beaver.rb,
lib/beaver/dam.rb,
lib/beaver/utils.rb,
lib/beaver/request.rb,
lib/beaver/version.rb,
lib/beaver/parsers/http.rb,
lib/beaver/parsers/rails.rb

Overview

A DSL and library for finding out how people are using your Rails app. Can also be used to parse/analyze HTTP access logs (Apache, Nginx, etc.)

# Parse and return the requests
requests = Beaver.parse('/path/to/log/files')

# Parse, filters, and returns the requests (all requests are always returned)
requests = Beaver.filter('/path/to/log/files') do
  hit :error, :status => (400..505) do
    puts "#{status} on #{path} at #{time} from #{ip} with #{params_str}"
  end
end

# Parse and filters the requests, returns nil
Beaver.stream('/path/to/log/files') do
  hit :error, :status => (400..505) do
    puts "#{status} on #{path} at #{time} from #{ip} with #{params_str}"
  end
end

Defined Under Namespace

Modules: Parsers, Utils Classes: Beaver, Dam, Request

Constant Summary collapse

VERSION =

:nodoc:

[MAJOR_VERSION, MINOR_VERSION, TINY_VERSION, PRE_VERSION].compact.join '.'

Class Method Summary collapse

Class Method Details

.dam(*args) ⇒ Object

Parses the logs and filters them through the provided matcher options. Returns only the matching requests.



43
44
45
46
47
48
49
# File 'lib/beaver/beaver.rb', line 43

def self.dam(*args)
  beaver = Beaver.new(*args)
  dam = beaver.hit :hits
  beaver.parse
  beaver.filter
  dam.hits
end

.filter(*args, &blk) ⇒ Object

Parses the logs and filters them through the given block. All parsed requests 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
30
31
# File 'lib/beaver/beaver.rb', line 29

def self.filter(*args, &blk)
  Beaver.new(*args, &blk).parse.filter.requests
end

.new(*args, &blk) ⇒ Object

Alias to Beaver::Beaver.new



52
53
54
# File 'lib/beaver/beaver.rb', line 52

def self.new(*args, &blk)
  Beaver.new(*args, &blk)
end

.parse(*args) ⇒ Object

Parses the logs and returns the requests.



23
24
25
# File 'lib/beaver/beaver.rb', line 23

def self.parse(*args)
  Beaver.new(*args).parse.requests
end

.stream(*args, &blk) ⇒ Object

Parses the logs and filters them through the (optional) block. Parsed requests are not retained, hence are not returned. Returns nil.

In theory, this should be more memory efficient than Beaver#filter.



37
38
39
40
# File 'lib/beaver/beaver.rb', line 37

def self.stream(*args, &blk)
  Beaver.new(*args, &blk).stream
  nil
end