Sha256: c846b1b1fceb578816b2649e0c8ee93d18b7343189f3eac065c7f04d35c35a38

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.io/terms.html

require 'sqreen/performance_notifications'

module Sqreen
  module PerformanceNotifications
    # Log performances in sqreen metrics_store
    class Metrics
      @subid = nil
      @facility = nil
      class << self
        EVENT_CAT = 'sqreen_time'.freeze
        def log(event, start, finish, _meta)
          evt = [EVENT_CAT, event, (finish - start) * 1000, SQREEN_MONO_TIME ? Time.now.utc : finish]
          Sqreen.observations_queue.push(evt)
        end

        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(nil,
                                                              &method(:log))
        end

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

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
sqreen-1.11.0-java lib/sqreen/performance_notifications/metrics.rb
sqreen-alt-1.11.0 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.11.0 lib/sqreen/performance_notifications/metrics.rb