Class: RailsPerformance::Models::RequestRecord
- Inherits:
-
BaseRecord
- Object
- BaseRecord
- RailsPerformance::Models::RequestRecord
- Defined in:
- lib/rails_performance/models/request_record.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#datetimei ⇒ Object
Returns the value of attribute datetimei.
-
#db_runtime ⇒ Object
Returns the value of attribute db_runtime.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#exception_object ⇒ Object
Returns the value of attribute exception_object.
-
#format ⇒ Object
Returns the value of attribute format.
-
#http_referer ⇒ Object
Returns the value of attribute http_referer.
-
#json ⇒ Object
Returns the value of attribute json.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#view_runtime ⇒ Object
Returns the value of attribute view_runtime.
Class Method Summary collapse
- .find_by(request_id:) ⇒ Object
-
.from_db(key, value) ⇒ Object
key = performance| controller|HomeController| action|index| format|html| status|200| datetime|20200124T0523| datetimei|1579861423| method|GET| path|/| request_id|454545454545454545| END|1.0.0 = divided by 0”,“backtrace”:[“/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in ‘/’”,“/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in ‘crash’”,“/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in ‘send_action’”] value = JSON.
Instance Method Summary collapse
- #controller_action ⇒ Object
- #controller_action_format ⇒ Object
-
#initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, exception: nil, exception_object: nil, json: '{}') ⇒ RequestRecord
constructor
A new instance of RequestRecord.
- #record_hash ⇒ Object
- #save ⇒ Object
Methods inherited from BaseRecord
Constructor Details
#initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, exception: nil, exception_object: nil, json: '{}') ⇒ RequestRecord
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rails_performance/models/request_record.rb', line 47 def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, exception: nil, exception_object: nil, json: '{}') @controller = controller @action = action @format = format @status = status @datetime = datetime @datetimei = datetimei.to_i @method = method @path = path @request_id = request_id @view_runtime = view_runtime @db_runtime = db_runtime @duration = duration @http_referer = http_referer @exception = Array.wrap(exception).compact.join(" ") @exception_object = exception_object @json = json end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def action @action end |
#controller ⇒ Object
Returns the value of attribute controller.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def controller @controller end |
#datetime ⇒ Object
Returns the value of attribute datetime.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def datetime @datetime end |
#datetimei ⇒ Object
Returns the value of attribute datetimei.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def datetimei @datetimei end |
#db_runtime ⇒ Object
Returns the value of attribute db_runtime.
5 6 7 |
# File 'lib/rails_performance/models/request_record.rb', line 5 def db_runtime @db_runtime end |
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/rails_performance/models/request_record.rb', line 5 def duration @duration end |
#exception ⇒ Object
Returns the value of attribute exception.
6 7 8 |
# File 'lib/rails_performance/models/request_record.rb', line 6 def exception @exception end |
#exception_object ⇒ Object
Returns the value of attribute exception_object.
6 7 8 |
# File 'lib/rails_performance/models/request_record.rb', line 6 def exception_object @exception_object end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def format @format end |
#http_referer ⇒ Object
Returns the value of attribute http_referer.
5 6 7 |
# File 'lib/rails_performance/models/request_record.rb', line 5 def http_referer @http_referer end |
#json ⇒ Object
Returns the value of attribute json.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def json @json end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def path @path end |
#request_id ⇒ Object
Returns the value of attribute request_id.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def request_id @request_id end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/rails_performance/models/request_record.rb', line 4 def status @status end |
#view_runtime ⇒ Object
Returns the value of attribute view_runtime.
5 6 7 |
# File 'lib/rails_performance/models/request_record.rb', line 5 def view_runtime @view_runtime end |
Class Method Details
.find_by(request_id:) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/rails_performance/models/request_record.rb', line 8 def RequestRecord.find_by(request_id:) keys, values = RailsPerformance::Utils.fetch_from_redis("performance|*|request_id|#{request_id}|*") return nil if keys.blank? return nil if values.blank? RailsPerformance::Models::RequestRecord.from_db(keys[0], values[0]) end |
.from_db(key, value) ⇒ Object
key = performance| controller|HomeController| action|index| format|html| status|200| datetime|20200124T0523| datetimei|1579861423| method|GET| path|/| request_id|454545454545454545| END|1.0.0
divided by 0”,“backtrace”:[“/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in ‘/’”,“/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in ‘crash’”,“/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in ‘send_action’”]
value = JSON
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_performance/models/request_record.rb', line 30 def RequestRecord.from_db(key, value) items = key.split("|") RequestRecord.new( controller: items[2], action: items[4], format: items[6], status: items[8], datetime: items[10], datetimei: items[12], method: items[14], path: items[16], request_id: items[18], json: value ) end |
Instance Method Details
#controller_action ⇒ Object
69 70 71 |
# File 'lib/rails_performance/models/request_record.rb', line 69 def controller_action "#{controller}##{action}" end |
#controller_action_format ⇒ Object
73 74 75 |
# File 'lib/rails_performance/models/request_record.rb', line 73 def controller_action_format "#{controller}##{action}|#{format}" end |
#record_hash ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rails_performance/models/request_record.rb', line 77 def record_hash { controller: self.controller, action: self.action, format: self.format, status: self.status, method: self.method, path: self.path, request_id: self.request_id, datetime: Time.at(self.datetimei.to_i), datetimei: datetimei, duration: self.value['duration'], db_runtime: self.value['db_runtime'], view_runtime: self.value['view_runtime'], exception: self.value['exception'], backtrace: self.value['backtrace'] } end |
#save ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rails_performance/models/request_record.rb', line 96 def save key = "performance|controller|#{controller}|action|#{action}|format|#{format}|status|#{status}|datetime|#{datetime}|datetimei|#{datetimei}|method|#{method}|path|#{path}|request_id|#{request_id}|END|#{RailsPerformance::SCHEMA}" value = { view_runtime: view_runtime, db_runtime: db_runtime, duration: duration, http_referer: http_referer, } value[:exception] = exception if exception.present? value[:backtrace] = exception_object.backtrace.take(3) if exception_object Utils.save_to_redis(key, value) end |