class Mongoid::Railties::ControllerRuntime::Collector
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.
Constants
- VARIABLE_NAME
Public Class Methods
Reset the runtime value to zero the current thread.
@return [ Integer ] The previous runtime value.
# File lib/mongoid/railties/controller_runtime.rb, line 96 def self.reset_runtime to_now = runtime self.runtime = 0 to_now end
Get the runtime value on the current thread.
@return [ Integer ] The runtime value.
# File lib/mongoid/railties/controller_runtime.rb, line 80 def self.runtime Threaded.get(VARIABLE_NAME) { 0 } end
Set the runtime value on the current thread.
@param [ Integer ] value The runtime value.
@return [ Integer ] The runtime value.
# File lib/mongoid/railties/controller_runtime.rb, line 89 def self.runtime= value Threaded.set(VARIABLE_NAME, value) end
Public Instance Methods
Call when event completed. Updates the runtime value.
@param [ Mongo::Event::Base ] e The monitoring event.
@return [ Integer ] The current runtime value.
# File lib/mongoid/railties/controller_runtime.rb, line 71 def _completed e Collector.runtime += e.duration * 1000 end
Call when event started. Does nothing.
@return [ nil ] Nil.
# File lib/mongoid/railties/controller_runtime.rb, line 64 def started _; end