Module: Sqreen::PerformanceNotifications
- Defined in:
- lib/sqreen/performance_notifications.rb,
lib/sqreen/performance_notifications/log.rb,
lib/sqreen/performance_notifications/metrics.rb,
lib/sqreen/performance_notifications/newrelic.rb,
lib/sqreen/performance_notifications/binned_metrics.rb,
lib/sqreen/performance_notifications/log_performance.rb
Overview
This module enable us to keep track of sqreen resource usage
It is inspired by ActiveSupport::Notifications
Defined Under Namespace
Classes: BinnedMetrics, Log, LogPerformance, Metrics, NewRelic
Class Method Summary collapse
-
.instrument(rule, cb, meta = {}, &block) ⇒ Object
Instrument a call identified by key.
-
.listen_for? ⇒ Boolean
Is there a subscriber.
- .notify(rule, cb, start, stop, meta = {}) ⇒ Object
-
.subscribe(&block) ⇒ Object
Subscribe to receive notifications about an event returns a subscription identification.
-
.unsubscribe(subscription) ⇒ Object
Unsubscrube for a given subscription.
-
.unsubscribe_all! ⇒ Object
Unsubscribe from everything not threadsafe.
Class Method Details
.instrument(rule, cb, meta = {}, &block) ⇒ Object
Instrument a call identified by key
31 32 33 34 |
# File 'lib/sqreen/performance_notifications.rb', line 31 def instrument(rule, cb, = {}, &block) return yield unless listen_for? _instrument(rule, cb, , &block) end |
.listen_for? ⇒ Boolean
Is there a subscriber
26 27 28 |
# File 'lib/sqreen/performance_notifications.rb', line 26 def listen_for? !@subscriptions_all.empty? end |
.notify(rule, cb, start, stop, meta = {}) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/sqreen/performance_notifications.rb', line 36 def notify(rule, cb, start, stop, = {}) return unless listen_for? notifiers.each do |callable| callable.call(rule, cb, start, stop, ) end end |
.subscribe(&block) ⇒ Object
Subscribe to receive notifications about an event returns a subscription identification
19 20 21 22 23 |
# File 'lib/sqreen/performance_notifications.rb', line 19 def subscribe(&block) id = (@subscription_id += 1) @subscriptions_all[id] = block id end |
.unsubscribe(subscription) ⇒ Object
Unsubscrube for a given subscription
44 45 46 |
# File 'lib/sqreen/performance_notifications.rb', line 44 def unsubscribe(subscription) return unless @subscriptions_all.delete(subscription).nil? end |
.unsubscribe_all! ⇒ Object
Unsubscribe from everything not threadsafe
50 51 52 |
# File 'lib/sqreen/performance_notifications.rb', line 50 def unsubscribe_all! @subscriptions_all.clear end |