Class: Mongrel::Proctitler
- Inherits:
-
Object
- Object
- Mongrel::Proctitler
- Defined in:
- lib/mongrel_proctitle.rb
Overview
Mongrel process title modification.
Instance Method Summary collapse
-
#initialize(port, prefix) ⇒ Proctitler
constructor
Initializes titler.
-
#port ⇒ Object
Returns port used in title.
-
#port=(new_port) ⇒ Object
Return port used in title.
- #request(&block) ⇒ Object
-
#revision ⇒ Object
Returns revision used in title.
-
#set_handling(request) ⇒ Object
Reports process as handling a socket.
-
#set_idle ⇒ Object
Reports process as being idle.
-
#set_processing(socket) ⇒ Object
Reports process as handling a socket.
- #set_request_list_title(excluding = nil) ⇒ Object
-
#title ⇒ Object
Returns current title.
-
#title=(title) ⇒ Object
Sets process title.
-
#update_process_title ⇒ Object
Updates the process title.
Constructor Details
#initialize(port, prefix) ⇒ Proctitler
Initializes titler.
9 10 11 12 13 14 15 16 17 |
# File 'lib/mongrel_proctitle.rb', line 9 def initialize(port, prefix) @prefix = prefix @port = port @mutex = Mutex.new @titles = [] @request_threads = [] @queue_length = 0 @request_count = 0 end |
Instance Method Details
#port ⇒ Object
Returns port used in title.
20 21 22 |
# File 'lib/mongrel_proctitle.rb', line 20 def port @port end |
#port=(new_port) ⇒ Object
Return port used in title.
25 26 27 |
# File 'lib/mongrel_proctitle.rb', line 25 def port=(new_port) @port = new_port end |
#request(&block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mongrel_proctitle.rb', line 34 def request(&block) titles, mutex = @titles, @mutex mutex.synchronize do @queue_length += 1 titles.push(self.title) end begin yield ensure mutex.synchronize do @queue_length -= 1 @request_count += 1 @request_threads.delete(Thread.current) set_request_list_title end end end |
#revision ⇒ Object
Returns revision used in title.
30 31 32 |
# File 'lib/mongrel_proctitle.rb', line 30 def revision @revision ||= get_app_revision if self.respond_to?(:get_app_revision) end |
#set_handling(request) ⇒ Object
Reports process as handling a socket.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mongrel_proctitle.rb', line 77 def set_handling(request) params = request.params address = params['REMOTE_ADDR'] method = params['REQUEST_METHOD'] path = params['REQUEST_PATH'] path = "#{path[0, 60]}..." if path.length > 60 Thread.current[:request_str] = "#{address}: #{method} #{path}" @request_threads.push(Thread.current) set_request_list_title(Thread.current) end |
#set_idle ⇒ Object
Reports process as being idle.
67 68 69 |
# File 'lib/mongrel_proctitle.rb', line 67 def set_idle self.title = "idle" end |
#set_processing(socket) ⇒ Object
Reports process as handling a socket.
72 73 74 |
# File 'lib/mongrel_proctitle.rb', line 72 def set_processing(socket) self.title = "handling #{socket.peeraddr.last}" end |
#set_request_list_title(excluding = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mongrel_proctitle.rb', line 52 def set_request_list_title(excluding = nil) if @request_threads.empty? set_idle else if defined?(Rails) # find the first awake/critical thread and put it in the front running_thread = @request_threads.detect {|thread| thread.status == "run" && excluding != thread } @request_threads.unshift(@request_threads.delete(running_thread)) if running_thread # this isn't exact, but it works for most situations end self.title = "handling #{@request_threads.collect {|t| t[:request_str]}.join(', ')}" end end |
#title ⇒ Object
Returns current title
89 90 91 |
# File 'lib/mongrel_proctitle.rb', line 89 def title @title end |
#title=(title) ⇒ Object
Sets process title.
94 95 96 97 |
# File 'lib/mongrel_proctitle.rb', line 94 def title=(title) @title = title update_process_title end |
#update_process_title ⇒ Object
Updates the process title.
100 101 102 103 104 105 106 107 108 |
# File 'lib/mongrel_proctitle.rb', line 100 def update_process_title title = "#{@prefix} [" title << (@port ? "#{@port}" : "?") title << (revision ? "/r#{revision}" : "") title << "/#{@queue_length}" title << "/#{@request_count}" title << "]: #{@title}" $0 = title end |