Sha256: bfab41c9f8b93a1a8191b9a23d6b16cce2cad5cc9f8c659c87d9d1e5362f7257

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require "harness/version"

require 'multi_json'

require 'redis'
require 'redis/namespace'

require 'active_support/notifications'
require 'active_support/core_ext/string'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/integer'

require 'active_support/ordered_options'

module Harness
  class LoggingError < RuntimeError ; end
  class NoCounter < RuntimeError ; end

  class Config
    attr_reader :adapter, :queue
    attr_accessor :namespace, :source
    attr_reader :instrument

    def initialize
      @instrument = ActiveSupport::OrderedOptions.new
    end

    def adapter=(val)
      if val.is_a? Symbol
        @adapter = "Harness::#{val.to_s.camelize}Adapter".constantize.new
      else
        @adapter = val
      end
    end

    def queue=(val)
      if val.is_a? Symbol
        @queue = "Harness::#{val.to_s.camelize}Queue".constantize.new
      else
        @queue = val
      end
    end

    def method_missing(name, *args, &block)
      begin
        "Harness::#{name.to_s.camelize}Adapter".constantize.config
      rescue NameError
        super
      end
    end
  end

  def self.config
    @config ||= Config.new
  end

  def self.log(measurement)
    config.queue.push measurement
  end

  def self.logger
    @logger
  end

  def self.logger=(logger)
    @logger = logger
  end

  def self.redis=(redis)
    @redis = redis
  end

  def self.redis
    @redis
  end

  def self.reset_counters!
    redis.smembers('counters').each do |counter|
      redis.set counter, 0
    end
  end
end

require 'harness/measurement'
require 'harness/counter'
require 'harness/gauge'

require 'harness/instrumentation'

require 'harness/job'

require 'harness/queues/synchronous_queue'

require 'harness/adapters/librato_adapter'
require 'harness/adapters/memory_adapter'
require 'harness/adapters/null_adapter'

require 'harness/railtie' if defined?(Rails)

require 'logger'

Harness.logger = Logger.new $stdout

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harness-0.9.0 lib/harness.rb