MetricsSourceMetricsConfig

class Config

Represents a configuration for the metrics library.

Definitions

def self.load(path)

Load the configuration from the given path.

Signature

parameter path String

The path to the configuration file.

returns Config

The loaded configuration.

Implementation

def self.load(path)
	config = self.new
	
	if File.exist?(path)
		config.instance_eval(File.read(path), path)
	end
	
	return config
end

def self.default

Load the default configuration.

Signature

returns Config

The default configuration.

Implementation

def self.default
	@default ||= self.load(DEFAULT_PATH)
end

def prepare

Prepare the backend, e.g. by loading additional libraries or instrumentation.

Implementation

def prepare
end

def require_backend(env = ENV)

Require a specific metrics backend implementation.

Implementation

def require_backend(env = ENV)
	if backend = env["METRICS_BACKEND"]
		begin
			if require(backend)
				Metrics.extend(Backend::Interface)
				
				return true
			end
		rescue LoadError => error
			warn "Unable to load metrics backend: #{backend.inspect}!"
		end
	end
	
	return false
end

DEFAULT = self.default

Load the default configuration.