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.
- data/README +6 -8
- data/lib/rawkx.rb +9 -7
- data/lib/stat_hash.rb +1 -1
- 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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
34
|
-
def parse_line(line)
|
34
|
+
RawkX.new do |line|
|
35
35
|
fields = line.split
|
36
|
-
|
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>
|
data/lib/rawkx.rb
CHANGED
@@ -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.
|
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
|
-
|
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
|
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
|
data/lib/stat_hash.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 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-
|
17
|
+
date: 2010-04-18 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|