Class: InstStatsd::SqlTracker
- Inherits:
-
Object
- Object
- InstStatsd::SqlTracker
- Defined in:
- lib/inst_statsd/sql_tracker.rb
Instance Attribute Summary collapse
-
#blocked_names ⇒ Object
readonly
Returns the value of attribute blocked_names.
-
#cache_counts ⇒ Object
readonly
Returns the value of attribute cache_counts.
-
#read_counts ⇒ Object
readonly
Returns the value of attribute read_counts.
-
#write_counts ⇒ Object
readonly
Returns the value of attribute write_counts.
Instance Method Summary collapse
- #finalize_counts(cookies) ⇒ Object
-
#initialize(opts = nil) ⇒ SqlTracker
constructor
A new instance of SqlTracker.
- #start ⇒ Object
- #track(name, sql) ⇒ Object
Constructor Details
#initialize(opts = nil) ⇒ SqlTracker
Returns a new instance of SqlTracker.
7 8 9 10 11 12 13 |
# File 'lib/inst_statsd/sql_tracker.rb', line 7 def initialize(opts = nil) opts ||= {} @blocked_names = opts.fetch(:blocked_names, []) @read_counts = opts.fetch(:read_counter, InstStatsd::Counter.new("sql.read")) @write_counts = opts.fetch(:write_counter, InstStatsd::Counter.new("sql.write")) @cache_counts = opts.fetch(:cache_counter, InstStatsd::Counter.new("sql.cache")) end |
Instance Attribute Details
#blocked_names ⇒ Object (readonly)
Returns the value of attribute blocked_names.
5 6 7 |
# File 'lib/inst_statsd/sql_tracker.rb', line 5 def blocked_names @blocked_names end |
#cache_counts ⇒ Object (readonly)
Returns the value of attribute cache_counts.
5 6 7 |
# File 'lib/inst_statsd/sql_tracker.rb', line 5 def cache_counts @cache_counts end |
#read_counts ⇒ Object (readonly)
Returns the value of attribute read_counts.
5 6 7 |
# File 'lib/inst_statsd/sql_tracker.rb', line 5 def read_counts @read_counts end |
#write_counts ⇒ Object (readonly)
Returns the value of attribute write_counts.
5 6 7 |
# File 'lib/inst_statsd/sql_tracker.rb', line 5 def write_counts @write_counts end |
Instance Method Details
#finalize_counts(cookies) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/inst_statsd/sql_tracker.rb', line 31 def finalize_counts() [ read_counts.finalize_count([0]), write_counts.finalize_count([1]), cache_counts.finalize_count([2]) ] end |
#start ⇒ Object
15 16 17 |
# File 'lib/inst_statsd/sql_tracker.rb', line 15 def start [read_counts, write_counts, cache_counts].map(&:start) end |
#track(name, sql) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/inst_statsd/sql_tracker.rb', line 19 def track(name, sql) return unless sql && accepted_name?(name) if name.include?("CACHE") cache_counts.track name elsif truncate(sql).include?("SELECT") || name.include?("LOAD") read_counts.track(sql) else write_counts.track(sql) end end |