Class: AwesomeExplain::Insights::MongoidInsights
- Inherits:
-
Object
- Object
- AwesomeExplain::Insights::MongoidInsights
- Defined in:
- lib/awesome_explain/insights/mongoid_insights.rb
Instance Attribute Summary collapse
-
#command_subscriber ⇒ Object
Returns the value of attribute command_subscriber.
-
#metrics ⇒ Object
Returns the value of attribute metrics.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#command_subscriber ⇒ Object
Returns the value of attribute command_subscriber.
3 4 5 |
# File 'lib/awesome_explain/insights/mongoid_insights.rb', line 3 def command_subscriber @command_subscriber end |
#metrics ⇒ Object
Returns the value of attribute metrics.
3 4 5 |
# File 'lib/awesome_explain/insights/mongoid_insights.rb', line 3 def metrics @metrics end |
Class Method Details
.analyze(metrics = [], &block) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/awesome_explain/insights/mongoid_insights.rb', line 5 def self.analyze(metrics = [], &block) instance = new instance.init instance.metrics = metrics block_result = instance.instance_eval(&block) instance.tear_down block_result unless metrics.size.positive? end |
Instance Method Details
#init ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/awesome_explain/insights/mongoid_insights.rb', line 14 def init command_subscribers = Mongoid.default_client.send(:monitoring).subscribers['Command'] || Mongo::Monitoring::Global.subscribers['Command'] @command_subscriber = command_subscribers.select do |s| s.class == AwesomeExplain::CommandSubscriber end.first @command_subscriber.clear Thread.current['ae_analyze'] = true Thread.current['ae_source'] = 'console' end |
#tear_down ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/awesome_explain/insights/mongoid_insights.rb', line 24 def tear_down if @command_subscriber.nil? puts 'Configure the command subscriber then try again.' return end if @metrics.size.positive? result = {} @metrics.each do |m| result[m] = @command_subscriber.get(m) end @command_subscriber.clear return result else @command_subscriber.clear end Thread.current['ae_analyze'] = false end |