Class: SoldierOfCode::DejaVu::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/deja-vu/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initializeAnalyzer

Returns a new instance of Analyzer.



7
8
9
# File 'lib/deja-vu/analyzer.rb', line 7

def initialize

end

Instance Method Details

#overview(specific_recording_pid = nil, start_stamp = nil, end_stamp = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/deja-vu/analyzer.rb', line 27

def overview(specific_recording_pid=nil, start_stamp=nil, end_stamp=nil)

  recordings = []
  unless specific_recording_pid
    # anlyize all the recordings as a mass
    DejaVuNS::Recording.all_recordings.each do |rec|
      recordings << rec
    end
  else
    # only analyize overview of the provided pid
    recordings << DejaVuNS::Recording.find_by_pid(specific_recording_pid)
  end

  perform_overview(recordings, start_stamp, end_stamp)

end

#overview_formatted(specific_recording_pid = nil, start_stamp = nil, end_stamp = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/deja-vu/analyzer.rb', line 11

def overview_formatted(specific_recording_pid=nil, start_stamp=nil, end_stamp=nil)
  ovr = overview(specific_recording_pid, start_stamp, end_stamp)

  puts "==================================================================================================="
  puts " Overview: #{ovr.analysis_title}"
  puts "==================================================================================================="
  puts " Number Of Requests: #{ovr.number_of_requests}"
  puts " Number Of Errors: #{ovr.number_of_errors}"
  puts " Percentage Success: #{ovr.success_percentile}%"
  puts " Average Response Time: #{ovr.avg_response_time}"
  puts " Number Of Unique Requests: #{ovr.number_of_unique_requests}"
  puts " Number Of Unique Users: #{ovr.number_of_unique_users}"

  #:number_of_requests, :number_of_errors, :success_percentile, :analysis_title, :avg_response_time, :number_of_unique_requests, :number_of_unique_users
end

#perform_overview(recordings, start_stamp = nil, end_stamp = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/deja-vu/analyzer.rb', line 44

def perform_overview(recordings, start_stamp=nil, end_stamp=nil)

  analysis = Analysis.new

  analysis.analysis_title = "Single User: #{recordings.first.ip}"

  records = []
  recordings.each do |rec|

    analysis.add_user

    rec.record.each do |record|
      if start_stamp && !end_stamp && record.stamp.to_i >= start_stamp # only a start stamp is provided so add all upto this date
        records << record
      elsif start_stamp && end_stamp && record.stamp.to_i >= start_stamp && record.stamp.to_i <= end_stamp # start and end stamps provided (envelope of time)
        records << record
      elsif !start_stamp && end_stamp && record.stamp.to_i <= end_stamp # Just an end time provided - everthing upto this time stamp
        records << record
      elsif !start_stamp && !end_stamp
        records << record
      end
    end
  end

  # these are vetted against the stamps
  urls_seen = []
  records.each do |record|

    analysis.add_request(record.request_time.to_f)

    unless urls_seen.include?(record.url)
      analysis.add_unique
      urls_seen << record.url
    end

    analysis.add_error if record.status.to_i >= 400

  end

  analysis
end