Class: Monitr
- Inherits:
-
Object
- Object
- Monitr
- Defined in:
- lib/monitr-rails.rb
Instance Method Summary collapse
-
#initialize(account_id) ⇒ Monitr
constructor
A new instance of Monitr.
- #log(controller, params = {}) ⇒ Object
Constructor Details
#initialize(account_id) ⇒ Monitr
Returns a new instance of Monitr.
6 7 8 9 |
# File 'lib/monitr-rails.rb', line 6 def initialize(account_id) @account_id = account_id @monitr_request_start = Time.now.to_f end |
Instance Method Details
#log(controller, params = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/monitr-rails.rb', line 11 def log(controller, params = {}) env_fields = %W( HTTP_USER_AGENT REQUEST_PATH CONTROLLER_NAME PATH_INFO REMOTE_ADDR ACCOUNT_ID REQUEST_PROCESS_TIME REQUEST_URI) env_fields.each do |label| params[label] = controller.request.env[label] end # This deals with Heroku passing the load balancers instead of the originating address if controller.request.env["HTTP_X_REAL_IP"] != nil params["REMOTE_ADDR"] = controller.request.env["HTTP_X_REAL_IP"] end if @monitr_request_start params["REQUEST_PROCESS_TIME"] = Time.now.to_f - @monitr_request_start end params["CONTROLLER_NAME"] = controller.controller_name params["ACTION_NAME"] = controller.action_name params["ACCOUNT_ID"] = @account_id begin params = data_to_cgi(params) url = "http://events.monitr.com/cgi-bin/monitr?" + params fp = open(url) data = fp.read fp.close rescue end end |