Class: Monitr

Inherits:
Object
  • Object
show all
Defined in:
lib/monitr-rails.rb

Instance Method Summary collapse

Constructor Details

#initialize(account_id, domain) ⇒ Monitr

Returns a new instance of Monitr.



6
7
8
9
10
# File 'lib/monitr-rails.rb', line 6

def initialize(, domain)
	@account_id = 
	@domain = domain
	@monitr_request_start = Time.now.to_f
end

Instance Method Details

#log(controller, params = {}) ⇒ Object



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
40
41
42
# File 'lib/monitr-rails.rb', line 12

def log(controller, params = {})
   env_fields = %W( HTTP_USER_AGENT REQUEST_PATH CONTROLLER_NAME PATH_INFO REMOTE_ADDR ACCOUNT_ID REQUEST_PROCESS_TIME)
   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

   params["DOMAIN"] = @domain

	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