Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Insights #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add initial metrics support to insights
  • Loading branch information
sandboxws committed Feb 25, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ddfb9c1c42f5d757fc52c64df1685991e4a93d43
7 changes: 7 additions & 0 deletions lib/awesome_explain/command_subscriber.rb
Original file line number Diff line number Diff line change
@@ -114,6 +114,13 @@ def formatted_collections
end.join("\n")
end

def get(metric)
case metric
when :total_performed_queries
total_performed_queries
end
end

def clear
init
end
21 changes: 16 additions & 5 deletions lib/awesome_explain/insights.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module AwesomeExplain
class Insights
attr_accessor :command_subscriber
attr_accessor :command_subscriber, :metrics

def self.analyze(&block)
def self.analyze(metrics = [], &block)
instance = new
instance.init
instance.metrics = metrics
instance.instance_eval(&block)
instance.tear_down
end
@@ -17,14 +18,24 @@ def init
end

def tear_down
# print stats to console
if @command_subscriber.nil?
puts 'Configure the command subscriber then try again.'
return
end

@command_subscriber.stats_table
@command_subscriber.clear
if @metrics.size.positive?
result = {}
@metrics.each do |m|
result[m] = @command_subscriber.get(m)
end

@command_subscriber.clear
return result
else
# print stats to console
@command_subscriber.stats_table
@command_subscriber.clear
end
end
end
end