module Hallmonitor::Monitored::ClassMethods
Public Instance Methods
count_for(method_sym, metric_name: nil, tags: {})
click to toggle source
Sets up a counter for a method by symbol. Method must have already been defined (ie. put this after the method definition) @param method_sym [Symbol] method name as a symbol @options [Hash] Optional settings:
metric_name: [String] Metric name to emit, defaults to "#{underscore(name)}.#{method_sym}"
# File lib/hallmonitor/monitored.rb, line 32 def count_for(method_sym, metric_name: nil, tags: {}) metric_name ||= "#{underscore(name)}.#{method_sym}" undecorated_method_sym = "#{method_sym}_without_hallmonitor_counter".to_sym decorated_method_sym = "#{method_sym}_with_hallmonitor_counter".to_sym send(:define_method, decorated_method_sym) do |*args| emit(metric_name, tags: tags) send(undecorated_method_sym, *args) end alias_method undecorated_method_sym, method_sym alias_method method_sym, decorated_method_sym end
timer_for(method_sym, metric_name: nil, tags: {})
click to toggle source
Sets up a timer for a method by symbol. Method must have already been defined (ie. put this after the method definition) @param method_sym [Symbol] method name as a symbol @options [Hash] Optional settings:
metric_name: [String] Metric name to emit, defaults to "#{underscore(name)}.#{method_sym}"
# File lib/hallmonitor/monitored.rb, line 12 def timer_for(method_sym, metric_name: nil, tags: {}) metric_name ||= "#{underscore(name)}.#{method_sym}" undecorated_method_sym = "#{method_sym}_without_hallmonitor_timer".to_sym decorated_method_sym = "#{method_sym}_with_hallmonitor_timer".to_sym send(:define_method, decorated_method_sym) do |*args| watch(metric_name, tags: tags) do send(undecorated_method_sym, *args) end end alias_method undecorated_method_sym, method_sym alias_method method_sym, decorated_method_sym end
underscore(value)
click to toggle source
:reek: UtilityFunction
# File lib/hallmonitor/monitored.rb, line 46 def underscore(value) word = value.dup word.gsub!(/::/, '.') word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!('-', ' ') word.downcase! word end