class Middleware::PageRequest
Object of this class is passed to the ActiveSupport::Notification hook
def call(name, started, finished, unique_id, payload)
def call(name, started, finished, unique_id, payload) # If the url contains any css or JavaScript files then do not collect metrics for them block_words = ["css", "assets", "jpg", "png", "jpeg", "ico"] if block_words.any? { |word| payload[:path].include?(word) } return nil end # Getting the endpoint and the content_type content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json"} content_type = content_hash[payload[:format]] if payload[:headers] request_path = URI(payload[:headers]['REQUEST_URI']).path.split(".")[0] else request_path = URI(payload[:path]).path.split(".")[0] end response_time = finished-started # Write to telegraf Middleware.write_to_telegraf("endpoint_name": request_path, "method_name": payload[:method], "status_code": payload[:status], "response_time": response_time, "db_runtime": payload[:db_runtime], "view_runtime": payload[:view_runtime], "content_type": content_type) end