pivotal-apdex 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -9,6 +9,10 @@ Usage
9
9
 
10
10
  egrep '/users/.+/edit' access.log | apdex_from_log --threshold 0.5 --time-column 11
11
11
 
12
+ # or
13
+
14
+ egrep '/users/.+/edit' access.log | awk '{print $11}' | apdex_from_log --threshold 0.5
15
+
12
16
 
13
17
  Example Output
14
18
  ==============
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
4
- :patch: 1
3
+ :minor: 2
4
+ :patch: 0
@@ -4,7 +4,7 @@ module Apdex
4
4
  attr_reader :time_column
5
5
 
6
6
  def initialize(params={})
7
- @time_column = params[:time_column] || raise(ArgumentError, "You must specify a time_column")
7
+ @time_column = params[:time_column]
8
8
  end
9
9
 
10
10
  def print(threshold, input)
@@ -18,9 +18,27 @@ module Apdex
18
18
  end
19
19
 
20
20
  def call(threshold, input)
21
- values = input.map do |line|
22
- `echo '#{line.strip}' | awk '{print $11}'`.strip.to_f
21
+ values = value_from_input(input)
22
+ output = categorize_values(values, threshold)
23
+ output[:score] = calculate_apdex(output)
24
+ output
25
+ end
26
+
27
+ protected
28
+
29
+ def value_from_input(input)
30
+ if time_column
31
+ input.map do |line|
32
+ `echo '#{line.strip}' | awk '{print $11}'`.strip.to_f
33
+ end
34
+ else
35
+ input.map do |line|
36
+ line.strip.to_f
37
+ end
23
38
  end
39
+ end
40
+
41
+ def categorize_values(values, threshold)
24
42
  output = {}
25
43
  output[:satisfied] = output[:tolerating] = output[:frustrated] = 0
26
44
  values.each do |value|
@@ -32,8 +50,15 @@ module Apdex
32
50
  output[:frustrated] += 1
33
51
  end
34
52
  end
35
- output[:score] = ("%0.3f" % (1.0 * (output[:satisfied] + output[:tolerating] / 2) / values.size)).to_f
36
53
  output
37
54
  end
55
+
56
+ def calculate_apdex(output)
57
+ raw_score = (1.0 *
58
+ (output[:satisfied] + (output[:tolerating]/2)) /
59
+ (output[:satisfied] + output[:tolerating] + output[:frustrated])
60
+ )
61
+ ("%0.3f" % raw_score).to_f
62
+ end
38
63
  end
39
64
  end
@@ -3,20 +3,35 @@ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3
3
  module Apdex
4
4
  describe CalculateFromLog do
5
5
  attr_reader :input, :command
6
- before do
6
+
7
+ def use_single_column_input
7
8
  @input = StringIO.new((<<-LOG).gsub(/^ +/, ""))
8
- 204.16.153.246 - performatron [23/Apr/2009:16:57:27 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4282 0.100 "-" "httperf/0.9.0" "-"
9
- 204.16.153.246 - performatron [23/Apr/2009:16:57:28 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4275 0.200 "-" "httperf/0.9.0" "-"
10
- 204.16.153.246 - performatron [23/Apr/2009:16:57:28 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4282 0.300 "-" "httperf/0.9.0" "-"
11
- 204.16.153.246 - performatron [23/Apr/2009:16:57:29 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4255 0.600 "-" "httperf/0.9.0" "-"
12
- 204.16.153.246 - performatron [23/Apr/2009:16:57:30 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4275 1.000 "-" "httperf/0.9.0" "-"
13
- 204.16.153.246 - performatron [23/Apr/2009:16:57:30 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4269 3.000 "-" "httperf/0.9.0" "-"
9
+ 0.100
10
+ 0.200
11
+ 0.300
12
+ 0.600
13
+ 1.000
14
+ 3.000
14
15
  LOG
16
+ end
15
17
 
16
- @command = CalculateFromLog.new(:time_column => 11)
18
+ def use_log_input
19
+ @input = StringIO.new((<<-LOG).gsub(/^ +/, ""))
20
+ 204.16.153.246 - performatron [23/Apr/2009:16:57:27 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4282 0.100 "-" "httperf/0.9.0" "-"
21
+ 204.16.153.246 - performatron [23/Apr/2009:16:57:28 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4275 0.200 "-" "httperf/0.9.0" "-"
22
+ 204.16.153.246 - performatron [23/Apr/2009:16:57:28 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4282 0.300 "-" "httperf/0.9.0" "-"
23
+ 204.16.153.246 - performatron [23/Apr/2009:16:57:29 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4255 0.600 "-" "httperf/0.9.0" "-"
24
+ 204.16.153.246 - performatron [23/Apr/2009:16:57:30 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4275 1.000 "-" "httperf/0.9.0" "-"
25
+ 204.16.153.246 - performatron [23/Apr/2009:16:57:30 -0700] "GET /myspace/compatibility/friend_model_matchings/new?model_id=17702&myspace_id=454017886 HTTP/1.1" 200 4269 3.000 "-" "httperf/0.9.0" "-"
26
+ LOG
17
27
  end
18
28
 
19
29
  describe "#print" do
30
+ before do
31
+ use_log_input
32
+ @command = CalculateFromLog.new(:time_column => 11)
33
+ end
34
+
20
35
  it "returns the Apdex output in a formatted string" do
21
36
  command.print(0.5, input).should == (<<-OUT).gsub(/^ +/, "").strip
22
37
  Score: 0.667
@@ -28,12 +43,34 @@ module Apdex
28
43
  end
29
44
 
30
45
  describe "#call" do
31
- it "returns the Apdex score based on the input log" do
32
- output = command.call(0.5, input)
33
- output[:satisfied].should == 3
34
- output[:tolerating].should == 2
35
- output[:frustrated].should == 1
36
- output[:score].should == 0.667
46
+ context "when the time column is not set" do
47
+ before do
48
+ use_single_column_input
49
+ @command = CalculateFromLog.new
50
+ end
51
+
52
+ it "returns the Apdex score based on the input" do
53
+ output = command.call(0.5, input)
54
+ output[:satisfied].should == 3
55
+ output[:tolerating].should == 2
56
+ output[:frustrated].should == 1
57
+ output[:score].should == 0.667
58
+ end
59
+ end
60
+
61
+ context "when the time column is set" do
62
+ before do
63
+ use_log_input
64
+ @command = CalculateFromLog.new(:time_column => 11)
65
+ end
66
+
67
+ it "returns the Apdex score based on the passed-in column in the input log" do
68
+ output = command.call(0.5, input)
69
+ output[:satisfied].should == 3
70
+ output[:tolerating].should == 2
71
+ output[:frustrated].should == 1
72
+ output[:score].should == 0.667
73
+ end
37
74
  end
38
75
  end
39
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal-apdex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Woolley
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-04-24 00:00:00 -07:00
14
+ date: 2009-04-25 00:00:00 -07:00
15
15
  default_executable: apdex_from_log
16
16
  dependencies: []
17
17