Class: WaterDrop::Instrumentation::Monitor
- Inherits:
-
Dry::Monitor::Notifications
- Object
- Dry::Monitor::Notifications
- WaterDrop::Instrumentation::Monitor
- Includes:
- Singleton
- Defined in:
- lib/water_drop/instrumentation/monitor.rb
Overview
This class acts as a singleton because we are only permitted to have single monitor per running process (just as logger)
Monitor is used to hookup external monitoring services to monitor how WaterDrop works Since it is a pub-sub based on dry-monitor, you can use as many subscribers/loggers at the same time, which means that you might have for example file logging and newrelic at the same time
Instance Method Summary collapse
-
#available_events ⇒ Array<String>
Names of available events to which we can subscribe.
-
#initialize ⇒ WaterDrop::Instrumentation::Monitor
constructor
Monitor instance for system instrumentation.
-
#subscribe(event_name_or_listener) ⇒ Object
Allows us to subscribe to events with a code that will be yielded upon events.
Constructor Details
#initialize ⇒ WaterDrop::Instrumentation::Monitor
Returns monitor instance for system instrumentation.
27 28 29 30 |
# File 'lib/water_drop/instrumentation/monitor.rb', line 27 def initialize super(:waterdrop) BASE_EVENTS.each(&method(:register_event)) end |
Instance Method Details
#available_events ⇒ Array<String>
Returns names of available events to which we can subscribe.
42 43 44 |
# File 'lib/water_drop/instrumentation/monitor.rb', line 42 def available_events __bus__.events.keys end |
#subscribe(event_name_or_listener) ⇒ Object
Allows us to subscribe to events with a code that will be yielded upon events
35 36 37 38 39 |
# File 'lib/water_drop/instrumentation/monitor.rb', line 35 def subscribe(event_name_or_listener) return super unless event_name_or_listener.is_a?(String) return super if available_events.include?(event_name_or_listener) raise Errors::UnregisteredMonitorEvent, event_name_or_listener end |