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.
6 7 8 9 10 11 12 |
# File 'lib/inst_statsd/sql_tracker.rb', line 6 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.
4 5 6 |
# File 'lib/inst_statsd/sql_tracker.rb', line 4 def blocked_names @blocked_names end |
#cache_counts ⇒ Object (readonly)
Returns the value of attribute cache_counts.
4 5 6 |
# File 'lib/inst_statsd/sql_tracker.rb', line 4 def cache_counts @cache_counts end |
#read_counts ⇒ Object (readonly)
Returns the value of attribute read_counts.
4 5 6 |
# File 'lib/inst_statsd/sql_tracker.rb', line 4 def read_counts @read_counts end |
#write_counts ⇒ Object (readonly)
Returns the value of attribute write_counts.
4 5 6 |
# File 'lib/inst_statsd/sql_tracker.rb', line 4 def write_counts @write_counts end |
Instance Method Details
#finalize_counts(cookies) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/inst_statsd/sql_tracker.rb', line 30 def finalize_counts() [ read_counts.finalize_count([0]), write_counts.finalize_count([1]), cache_counts.finalize_count([2]) ] end |
#start ⇒ Object
14 15 16 |
# File 'lib/inst_statsd/sql_tracker.rb', line 14 def start [read_counts, write_counts, cache_counts].map(&:start) end |
#track(name, sql) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/inst_statsd/sql_tracker.rb', line 18 def track name, sql return unless sql && accepted_name?(name) if name.match(/CACHE/) cache_counts.track name elsif truncate(sql).match(/SELECT/) || name.match(/LOAD/) read_counts.track(sql) else write_counts.track(sql) end end |