Module: Hallmonitor::Monitored
- Included in:
- Event
- Defined in:
- lib/hallmonitor/monitored.rb
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
57 58 59 60 |
# File 'lib/hallmonitor/monitored.rb', line 57 def self.included(base) base.extend(ClassMethods) base.extend(self) end |
Instance Method Details
#emit(event = nil, tags: {}) {|to_emit| ... } ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hallmonitor/monitored.rb', line 72 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
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hallmonitor/monitored.rb', line 90 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 |