Class: Metrics::Agent

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/ruby-metrics/agent.rb,
lib/ruby-metrics/integration/webrick.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(options = {}) ⇒ Agent

Returns a new instance of Agent.



23
24
25
# File 'lib/ruby-metrics/agent.rb', line 23

def initialize(options = {})
  @instruments = {}
end

Instance Attribute Details

#instrumentsObject (readonly) Also known as: registered

Returns the value of attribute instruments.



21
22
23
# File 'lib/ruby-metrics/agent.rb', line 21

def instruments
  @instruments
end

Instance Method Details

#as_json(*_) ⇒ Object



56
57
58
# File 'lib/ruby-metrics/agent.rb', line 56

def as_json(*_)
  @instruments
end

#counter(name) ⇒ Object



29
30
31
# File 'lib/ruby-metrics/agent.rb', line 29

def counter(name)
  @instruments[name] ||= Instruments::Counter.new
end

#exponential_histogram(name) ⇒ Object



52
53
54
# File 'lib/ruby-metrics/agent.rb', line 52

def exponential_histogram(name)
  @instruments[name] ||= Instruments::ExponentialHistogram.new
end

#gauge(name, &block) ⇒ Object



37
38
39
# File 'lib/ruby-metrics/agent.rb', line 37

def gauge(name, &block)
  @instruments[name] ||= Instruments::Gauge.new(&block)
end

#meter(name, options = {}) ⇒ Object



33
34
35
# File 'lib/ruby-metrics/agent.rb', line 33

def meter(name, options = {})
  @instruments[name] ||= options[:post_process] ? Instruments::PostProcessMeter.new(options) : Instruments::Meter.new(options)
end

#start(options = {}) ⇒ Object



8
9
10
# File 'lib/ruby-metrics/integration/webrick.rb', line 8

def start(options = {})
  Integration::WEBrick.start(options.merge(:agent => self))
end

#timer(name, options = {}) ⇒ Object



41
42
43
# File 'lib/ruby-metrics/agent.rb', line 41

def timer(name, options = {})
  @instruments[name] ||= options[:post_process] ? Instruments::PostProcessTimer.new(options) : Instruments::Timer.new(options)
end

#to_json(*_) ⇒ Object



60
61
62
# File 'lib/ruby-metrics/agent.rb', line 60

def to_json(*_)
  as_json.to_json
end

#uniform_histogram(name) ⇒ Object Also known as: histogram



45
46
47
# File 'lib/ruby-metrics/agent.rb', line 45

def uniform_histogram(name)
  @instruments[name] ||= Instruments::UniformHistogram.new
end