Class: Sqreen::PerformanceNotifications::Metrics

Inherits:
Log
  • Object
show all
Defined in:
lib/sqreen/performance_notifications/metrics.rb

Overview

Log performances in sqreen metrics_store

Constant Summary collapse

EVENT_CAT =
'sqreen_time'.freeze

Class Method Summary collapse

Methods inherited from Log

event_name

Class Method Details

.disableObject



32
33
34
35
36
# File 'lib/sqreen/performance_notifications/metrics.rb', line 32

def disable
  return if @subid.nil?
  Sqreen::PerformanceNotifications.unsubscribe(@subid)
  @subid = nil
end

.enable(metrics_engine, period = 60) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/sqreen/performance_notifications/metrics.rb', line 24

def enable(metrics_engine, period = 60)
  return unless @subid.nil?
  metrics_engine.create_metric('name' => EVENT_CAT,
                               'period' => period,
                               'kind' => 'Average')
  @subid = Sqreen::PerformanceNotifications.subscribe(&method(:log))
end

.log(rule, cb, start, finish, _meta) ⇒ Object



18
19
20
21
22
# File 'lib/sqreen/performance_notifications/metrics.rb', line 18

def log(rule, cb, start, finish, _meta)
  event = event_name(rule, cb)
  evt = [EVENT_CAT, event, (finish - start) * 1000, Time.now.utc]
  Sqreen.observations_queue.push(evt)
end