rawkx 0.1.0 → 0.2.0

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.
Files changed (4) hide show
  1. data/README +6 -8
  2. data/lib/rawkx.rb +9 -7
  3. data/lib/stat_hash.rb +1 -1
  4. metadata +3 -3
data/README CHANGED
@@ -8,9 +8,10 @@ RawkX is mostly a reorganization of this functionality to make extending the ana
8
8
  This gem is designed to allow users to easily extend the Rawk analyzer to have it use a seperate method for parsing.
9
9
  This will enable the analyzer to parse and perform calculations on logs of any format, not just Rails logs.
10
10
 
11
- This is done by simply overriding the 'parse_line' method used by RawkX to obtain a key/value pair for tracking times (values) associated with
12
- their action/request (keys). Upon doing this, you can call RawkX as you normally would and can get all the useful statistics you would normally
13
- get against any Rails log.
11
+ To tell RawkX how to parse your log format, you can pass it a block when creating a new RawkX object where the block will be used to parse each line of
12
+ the log to return a key/value pair. the key is the action you are measuring and the value is the time it took to complete on that particular execution.
13
+ see below for an example of this usage.
14
+
14
15
 
15
16
  Also note: by default (no override of parse_line), RawkX has the ability to parse Rails logs as Rawk always has.
16
17
 
@@ -30,13 +31,10 @@ You could create a simple ruby file which contains the following:
30
31
  require "rubygems"
31
32
  require "rawkx"
32
33
 
33
- class RawkX
34
- def parse_line(line)
34
+ RawkX.new do |line|
35
35
  fields = line.split
36
- return fields[1], fields[0]
37
- end
36
+ [fields[1], fields[0]]
38
37
  end
39
- RawkX.new
40
38
  --------------------------------------------------
41
39
 
42
40
  this file can be run with the command: ruby <ruby_file_name> -f <log_file_name>
@@ -6,7 +6,7 @@ require "#{File.expand_path(File.dirname(__FILE__))}/line_parser"
6
6
  class RawkX
7
7
  include LineParser
8
8
 
9
- VERSION = "0.1.0"
9
+ VERSION = "0.2.0"
10
10
  HEADER = "Request Count Sum Max Median Avg Min Std"
11
11
  HELP = "\nRawkX - Extendedable Rawk v#{VERSION}\n"+
12
12
  "Created by Peter Zimbelman\n"+
@@ -18,14 +18,14 @@ class RawkX
18
18
  " -s <count> Display <count> results in each group of data.\n\n"+
19
19
  " -w <count> Display the top <count> worst requests.\n\n"
20
20
 
21
- def initialize
21
+ def initialize(&block)
22
22
  @start_time = Time.now
23
23
  build_arg_hash
24
24
  if @arg_hash.keys.include?("h")
25
25
  puts HELP
26
26
  else
27
27
  init_args
28
- build_stats
28
+ build_stats(&block)
29
29
  print_stats
30
30
  end
31
31
  end
@@ -35,7 +35,7 @@ class RawkX
35
35
  def build_arg_hash
36
36
  @arg_hash = Hash.new
37
37
  last_key=nil
38
- for a in $*
38
+ $*.each do |a|
39
39
  if a.index("-")==0 && a.length>1
40
40
  a[1,1000].scan(/[a-z]|\?/).each {|c| @arg_hash[last_key=c]=nil}
41
41
  @arg_hash[last_key] = a[/\d+/] if last_key
@@ -57,9 +57,9 @@ class RawkX
57
57
 
58
58
  def build_stats
59
59
  while line = @input.gets
60
- key, time = parse_line(line)
61
- next unless key
62
- time = time.to_f unless time.is_a? Float
60
+ key, time = block_given? ? yield(line) : parse_line(line)
61
+ next unless key && time
62
+ time = time.to_f
63
63
  @stat_hash.add(key,time)
64
64
  @total_stat.add(time)
65
65
  if is_a_worst_request?(time)
@@ -107,4 +107,6 @@ class RawkX
107
107
  @worst_requests.each {|w| puts w[1]}
108
108
  puts "\nCompleted report in #{(Time.now-@start_time)/60.0} minutes"
109
109
  end
110
+
111
+
110
112
  end
@@ -17,7 +17,7 @@ class StatHash
17
17
  }
18
18
  #values.sort! {|a,b| a.key<=>b.key}
19
19
  limit = args[:limit]
20
- for stat in values
20
+ values.each do |stat|
21
21
  break if limit && limit<=0
22
22
  puts stat.to_s
23
23
  limit-=1 if limit
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Peter Zimbelman
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-14 00:00:00 -04:00
17
+ date: 2010-04-18 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20