123456789_123456789_123456789_123456789_123456789_

Class: Mongoid::Railties::ControllerRuntime::Collector

Relationships & Source Files
Inherits: Object
Defined in: lib/mongoid/railties/controller_runtime.rb

Overview

The Collector of MongoDB runtime metric, that subscribes to Mongo driver command monitoring. Stores the value within a thread-local variable to provide correct accounting when an application issues MongoDB operations from background threads.

Constant Summary

Class Attribute Summary

Class Method Summary

Instance Method Summary

Class Attribute Details

.runtimeInteger (rw)

Get the runtime value on the current thread.

Returns:

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 80

def self.runtime
  Threaded.get(VARIABLE_NAME) { 0 }
end

.runtime=(value) ⇒ Integer (rw)

::Set the runtime value on the current thread.

Parameters:

  • value (Integer)

    The runtime value.

Returns:

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 89

def self.runtime= value
  Threaded.set(VARIABLE_NAME, value)
end

Class Method Details

.reset_runtimeInteger

Reset the runtime value to zero the current thread.

Returns:

  • (Integer)

    The previous runtime value.

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 96

def self.reset_runtime
  to_now = runtime
  self.runtime = 0
  to_now
end

Instance Method Details

#_completed(e) ⇒ Integer Also known as: #succeeded, #failed

Call when event completed. Updates the runtime value.

Parameters:

  • e (Mongo::Event::Base)

    The monitoring event.

Returns:

  • (Integer)

    The current runtime value.

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 71

def _completed e
  Collector.runtime += e.duration * 1000
end

#failed(e)

Alias for #_completed.

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 75

alias :failed :_completed

#started(_) ⇒ nil

Call when event started. Does nothing.

Returns:

  • (nil)

    Nil.

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 64

def started _; end

#succeeded(e)

Alias for #_completed.

[ GitHub ]

  
# File 'lib/mongoid/railties/controller_runtime.rb', line 74

alias :succeeded :_completed