Sha256: c7cd9c37d7ece65153a44b1903ebe5dca51f6bdd8be37c08d7608cd7e5cbf4e4

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

# typed: ignore

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

require 'sqreen/performance_notifications'
require 'sqreen/performance_notifications/log'
require 'sqreen/runner'

module Sqreen
  module PerformanceNotifications
    # Log performances in sqreen metrics_store
    class Metrics < Log
      @subid = nil
      @facility = nil
      class << self
        EVENT_CAT = 'sqreen_time'.freeze
        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

        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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sqreen-1.25.1 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.25.0 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.24.3 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.24.2 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.24.1 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.24.0 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.23.2 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.23.1 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.23.0 lib/sqreen/performance_notifications/metrics.rb
sqreen-1.22.1 lib/sqreen/performance_notifications/metrics.rb