Sha256: dc7400d177eab2abf9cee3f5bb210dcfa16c874608971d06d9be09364a03fcf7

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'instrumental/agent'
require 'instrumental/configuration'
require 'instrumental/intervalometer'

module Instrumental

  @config = Configuration.new

  def self.configure
    yield @config
  end

  def self.boot!
    if @config.enabled?

      if defined?(PhusionPassenger)
        PhusionPassenger.on_event(:starting_worker_process) do
          @config.logger.debug('Starting a new worker process')
          Agent.instance.setup_and_run
        end

        PhusionPassenger.on_event(:stopping_worker_process) do
          @config.logger.debug('Killing worker process')
          Agent.instance.stop
        end

      else
        @config.logger.debug('Starting a new worker process')
        Agent.instance.setup_and_run
      end
    end
  end

  def self.config
    @config
  end

  def self.count(name, value=1)
    Agent.instance.report(:count, name, value)
  end

  def self.measure(name, value)
    Agent.instance.report(:measure, name, value)
  end

  def self.timer(name)
    start_time = Time.now
    yield
    self.measure(name, (Time.now - start_time) * 1000) # milliseconds
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
instrumental-0.1.5 lib/instrumental.rb