Class: Ap4r::Mongrel::Ap4rMonitoringHandler
- Inherits:
-
Mongrel::HttpHandler
- Object
- Mongrel::HttpHandler
- Ap4r::Mongrel::Ap4rMonitoringHandler
- Defined in:
- lib/ap4r/mongrel.rb
Overview
This class is an experimental implementation of monitoring API by HTTP. It’s possible to get the number of message in an arbitrary queue and the number of (alive/dead) thread of dispatchers.
=== Rrequest example ===
GET /mointoring/queues/queue.test HTTP/1.1
GET /mointoring/queues/all HTTP/1.1
GET /mointoring/queues/dlq HTTP/1.1
GET /mointoring/dispatchers/alive_threads HTTP/1.1
GET /mointoring/dispatchers/dead_threads HTTP/1.1
Instance Method Summary collapse
-
#initialize(options) ⇒ Ap4rMonitoringHandler
constructor
A new instance of Ap4rMonitoringHandler.
- #process(request, response) ⇒ Object
-
#reload! ⇒ Object
Does the internal reload for Rails.
Constructor Details
#initialize(options) ⇒ Ap4rMonitoringHandler
Returns a new instance of Ap4rMonitoringHandler.
308 309 310 311 312 313 |
# File 'lib/ap4r/mongrel.rb', line 308 def initialize() @tick = Time.now dlq = ReliableMsg::Queue.new "$dlq" @qm = dlq.send :qm end |
Instance Method Details
#process(request, response) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/ap4r/mongrel.rb', line 315 def process(request, response) if response.socket.closed? return end target = request.params[::Mongrel::Const::PATH_INFO][1..-1] if "GET".include? request.params[::Mongrel::Const::REQUEST_METHOD] begin # TODO: consider URL for each target, 2008/02/28 by kiwamu result = case target when /^queues\/*(\S*)/ case queue_name = $1 when "" @qm.store.queues.keys.join(" ") when "dlq" @qm.store.queues["$dlq"].size when "all" @qm.store.queues.map{|k,v| v.size}.sum else @qm.store.queues[queue_name].size end when /^dispatchers\/*(\S*)/ case $1 when "alive_threads" @qm.dispatchers.group.list.size when "dead_threads" diff = @qm.dispatchers.config.map{|d| d["threads"]}.sum - @qm.dispatchers.group.list.size diff > 0 ? diff : 0 else raise end else raise end response.start(200) do |head, out| head['Content-Type'] = 'text/plain' out.write result end rescue response.start(500) do |head, out| head['Content-Type'] = 'text/plain' out.write "Failed to monitor #{target}" end end else raise "HTTP method is not GET..." end end |
#reload! ⇒ Object
Does the internal reload for Rails. It might work for most cases, but sometimes you get exceptions. In that case just do a real restart.
368 369 370 371 372 373 |
# File 'lib/ap4r/mongrel.rb', line 368 def reload! begin #TODO not implemented 2007/04/09 by shino raise "not yet implemented!" end end |