Class: Metrics
- Inherits:
-
Object
- Object
- Metrics
- Defined in:
- lib/rails_requests/metrics.rb
Instance Method Summary collapse
-
#call(event_name, started, finished, event_id, payload) ⇒ Object
payload { controller: “PostsController”, action: “index”, params: => “index”, “controller” => “posts”, headers: #<ActionDispatch::Http::Headers:0x0055a67a519b88>, format: :html, method: “GET”, path: “/posts”, status: 200, view_runtime: 46.848, db_runtime: 0.157 }.
- #set(key, value) ⇒ Object
Instance Method Details
#call(event_name, started, finished, event_id, payload) ⇒ Object
payload
controller: "PostsController",
action: "index",
params: {"action" => "index", "controller" => "posts",
headers: #<ActionDispatch::Http::Headers:0x0055a67a519b88>,
format: :html,
method: "GET",
path: "/posts",
status: 200,
view_runtime: 46.848,
db_runtime: 0.157
}
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_requests/metrics.rb', line 17 def call(event_name, started, finished, event_id, payload) event = ActiveSupport::Notifications::Event.new(event_name, started, finished, event_id, payload) record = { controller: event.payload[:controller], action: event.payload[:action], format: event.payload[:format], method: event.payload[:method], path: event.payload[:path], status: event.payload[:status], view_runtime: event.payload[:view_runtime], db_runtime: event.payload[:db_runtime], duration: event.duration } namespace = "metrics|#{record[:controller]}|#{record[:action]}|#{finished.strftime("%Y%m%dT%H%M")}|#{finished.to_i}|#{record[:path]}" # set("#{namespace}|all", record.to_json) # set("#{namespace}|database", record[:db_runtime]) # set("#{namespace}|view_duration", record[:view_runtime]) set("#{namespace}|total_duration", record[:duration]) end |
#set(key, value) ⇒ Object
40 41 42 43 44 |
# File 'lib/rails_requests/metrics.rb', line 40 def set(key, value) #puts "#{key} = #{value}" RailsRequests.redis.set(key, value) RailsRequests.redis.expire(key, RailsRequests.duration.to_i) end |