Module: Hallmonitor::Monitored
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #emit(event = nil, tags: {}) {|to_emit| ... } ⇒ Object
-
#watch(name, tags: {}) {|event| ... } ⇒ Object
Executes and times a block of code and emits a TimedEvent.
Class Method Details
.included(base) ⇒ Object
52 53 54 |
# File 'lib/hallmonitor/monitored.rb', line 52 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#emit(event = nil, tags: {}) {|to_emit| ... } ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hallmonitor/monitored.rb', line 65 def emit(event = nil, tags: {}) to_emit = self unless event.nil? to_emit = event.is_a?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event, tags: ) end # If we were given a block, then we want to execute that yield(to_emit) if block_given? Dispatcher.output(to_emit) nil end |
#watch(name, tags: {}) {|event| ... } ⇒ Object
Note:
Will emit the timed event even if the block raises an error
Executes and times a block of code and emits a TimedEvent
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/hallmonitor/monitored.rb', line 83 def watch(name, tags: {}) event = Hallmonitor::TimedEvent.new(name, tags: ) event.start = Time.now begin yield(event) ensure event.stop = Time.now emit(event) end end |