Class: ReportsMash::Engine::Transaction
- Inherits:
-
Object
- Object
- ReportsMash::Engine::Transaction
- Defined in:
- lib/reportsmash/engine/transaction.rb
Instance Attribute Summary collapse
-
#db_duration_ms ⇒ Object
Returns the value of attribute db_duration_ms.
-
#db_transactions ⇒ Object
Returns the value of attribute db_transactions.
-
#external_http_duration_ms ⇒ Object
Returns the value of attribute external_http_duration_ms.
-
#external_http_requests ⇒ Object
Returns the value of attribute external_http_requests.
-
#memcached_ops ⇒ Object
Returns the value of attribute memcached_ops.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#redis_ops ⇒ Object
Returns the value of attribute redis_ops.
-
#render_duration_ms ⇒ Object
Returns the value of attribute render_duration_ms.
-
#render_transactions ⇒ Object
Returns the value of attribute render_transactions.
-
#user_params ⇒ Object
Returns the value of attribute user_params.
Instance Method Summary collapse
- #add_user_params(new_params) ⇒ Object
- #end(start_time, stop_time, status_code, headers) ⇒ Object
-
#initialize(engine, request) ⇒ Transaction
constructor
A new instance of Transaction.
- #tid ⇒ Object
Constructor Details
#initialize(engine, request) ⇒ Transaction
Returns a new instance of Transaction.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/reportsmash/engine/transaction.rb', line 9 def initialize(engine, request) @engine = engine @request = request @response = nil @tid = SecureRandom.uuid @user_params = [] @start_time = nil @total_duration_ms = 0 @db_duration_ms = 0 @render_duration_ms = 0 @payload = {} @db_transactions = [] @render_transactions = [] @external_http_requests = [] @external_http_duration_ms = 0 @memcached_ops = [] @redis_ops = [] end |
Instance Attribute Details
#db_duration_ms ⇒ Object
Returns the value of attribute db_duration_ms.
5 6 7 |
# File 'lib/reportsmash/engine/transaction.rb', line 5 def db_duration_ms @db_duration_ms end |
#db_transactions ⇒ Object
Returns the value of attribute db_transactions.
5 6 7 |
# File 'lib/reportsmash/engine/transaction.rb', line 5 def db_transactions @db_transactions end |
#external_http_duration_ms ⇒ Object
Returns the value of attribute external_http_duration_ms.
6 7 8 |
# File 'lib/reportsmash/engine/transaction.rb', line 6 def external_http_duration_ms @external_http_duration_ms end |
#external_http_requests ⇒ Object
Returns the value of attribute external_http_requests.
6 7 8 |
# File 'lib/reportsmash/engine/transaction.rb', line 6 def external_http_requests @external_http_requests end |
#memcached_ops ⇒ Object
Returns the value of attribute memcached_ops.
7 8 9 |
# File 'lib/reportsmash/engine/transaction.rb', line 7 def memcached_ops @memcached_ops end |
#payload ⇒ Object
Returns the value of attribute payload.
4 5 6 |
# File 'lib/reportsmash/engine/transaction.rb', line 4 def payload @payload end |
#redis_ops ⇒ Object
Returns the value of attribute redis_ops.
7 8 9 |
# File 'lib/reportsmash/engine/transaction.rb', line 7 def redis_ops @redis_ops end |
#render_duration_ms ⇒ Object
Returns the value of attribute render_duration_ms.
5 6 7 |
# File 'lib/reportsmash/engine/transaction.rb', line 5 def render_duration_ms @render_duration_ms end |
#render_transactions ⇒ Object
Returns the value of attribute render_transactions.
5 6 7 |
# File 'lib/reportsmash/engine/transaction.rb', line 5 def render_transactions @render_transactions end |
#user_params ⇒ Object
Returns the value of attribute user_params.
3 4 5 |
# File 'lib/reportsmash/engine/transaction.rb', line 3 def user_params @user_params end |
Instance Method Details
#add_user_params(new_params) ⇒ Object
32 33 34 |
# File 'lib/reportsmash/engine/transaction.rb', line 32 def add_user_params(new_params) @user_params.merge!(new_params) if new_params.is_a? Hash end |
#end(start_time, stop_time, status_code, headers) ⇒ Object
36 37 38 39 40 41 42 43 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/reportsmash/engine/transaction.rb', line 36 def end(start_time, stop_time, status_code, headers) @start_time = start_time response_content_type = (headers && headers["Content-Type"]) ? headers["Content-Type"] : "" @total_duration_ms = (stop_time - start_time) * 1000.0 path_params = @request["action_dispatch.request.path_parameters"] controller_action = "static_file_server" if path_params && path_params.key?(:controller) && path_params.key?(:action) controller_action = path_params[:controller]+"#"+path_params[:action] end @memcached_stats = {} mc_duration_ms = 0 mc_counter = 0 if @memcached_ops.count > 0 %w[get set get_multi].each do |op| stat = {count: 0, duration_ms: 0, avg_ms: 0} @memcached_ops.select{|h| h.key? op.to_sym}.each do |trace| stat[:count] += 1 stat[:duration_ms] += trace[op.to_sym] stat[:avg_ms] = (stat[:duration_ms]/Float(stat[:count])).round(2) @memcached_stats[op.to_sym] = stat mc_duration_ms += stat[:duration_ms] mc_counter += 1 end end #puts "GOT MC_OPS #{@memcached_ops.inspect}: #{@memcached_stats.inspect}" end @redis_stats = {} redis_duration_ms = 0 redis_counter = 0 if @redis_ops.count > 0 %w[get set].each do |op| stat = {count: 0, duration_ms: 0, avg_ms: 0} @redis_ops.select{|h| h.key? op.to_sym}.each do |trace| stat[:count] += 1 stat[:duration_ms] += trace[op.to_sym] stat[:avg_ms] = (stat[:duration_ms]/Float(stat[:count])).round(2) @redis_stats[op.to_sym] = stat redis_duration_ms += stat[:duration_ms] redis_counter += 1 end end #puts "GOT REDIS_OPS #{@redis_ops.inspect}: #{@redis_stats.inspect}" end @payload = { :time_utc => @start_time.utc.to_i, :user_ip => @request["REMOTE_ADDR"], :user_agent => @request["HTTP_USER_AGENT"], :method => @request["REQUEST_METHOD"], :http_host => @request["HTTP_HOST"], :request_uri => @request["REQUEST_URI"], :request_path => @request["REQUEST_PATH"], :controller_action => controller_action, :response_content_type => response_content_type, :status => status_code, :total_duration_ms => @total_duration_ms.round(2), :db_duration_ms => @db_duration_ms.round(2), :render_duration_ms => @render_duration_ms.round(2), :external_http_duration_ms => @external_http_duration_ms.round(2), :external_memcache_duration_ms => mc_duration_ms.round(2), :external_redis_duration_ms => redis_duration_ms.round(2), :db_counter => @db_transactions.count, :render_counter => @render_transactions.count, :external_http_counter => @external_http_requests.count, :external_memcache_counter => mc_counter, :external_redis_counter => redis_counter, :db_transactions => @db_transactions, :render_transactions => @render_transactions, :external_http_requests => @external_http_requests, :external_memcache_requests => @memcached_stats, :external_redis_requests => @redis_stats, :custom_attributes => @user_params } end |
#tid ⇒ Object
28 29 30 |
# File 'lib/reportsmash/engine/transaction.rb', line 28 def tid @tid end |