Module: Librato::Metrics::Processor

Included in:
Aggregator, Queue
Defined in:
lib/librato/metrics/processor.rb

Constant Summary collapse

MEASUREMENTS_PER_REQUEST =
500

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_submit_timeObject (readonly)

Returns the value of attribute last_submit_time.



7
8
9
# File 'lib/librato/metrics/processor.rb', line 7

def last_submit_time
  @last_submit_time
end

#per_requestObject (readonly)

Returns the value of attribute per_request.



7
8
9
# File 'lib/librato/metrics/processor.rb', line 7

def per_request
  @per_request
end

Instance Method Details

#clientLibrato::Metrics::Client

The current Client instance this queue is using to authenticate and connect to Librato Metrics. This will default to the primary client used by the Librato::Metrics module unless it has been set to something else.



15
16
17
# File 'lib/librato/metrics/processor.rb', line 15

def client
  @client ||= Librato::Metrics.client
end

#persisterObject

The object this MetricSet will use to persist



21
22
23
# File 'lib/librato/metrics/processor.rb', line 21

def persister
  @persister ||= create_persister
end

#submitObject

Persist currently queued metrics

Returns:

  • Boolean

Raises:



28
29
30
31
32
33
34
35
36
# File 'lib/librato/metrics/processor.rb', line 28

def submit
  raise(NoMetricsQueued, "No metrics queued.") if self.queued.empty?
  options = {:per_request => @per_request}
  if persister.persist(self.client, self.queued, options)
    @last_submit_time = Time.now
    flush and return true
  end
  false
end

#time(name, options = {}) ⇒ Object Also known as: benchmark

Capture execution time for a block and queue it as the value for a metric. Times are recorded in milliseconds.

Options are the same as for #add.

Examples:

Queue API request response time

queue.time :api_request_time do
  # API request..
end

Queue API request response time w/ source

queue.time :api_request_time, :source => 'app1' do
  # API request..
end

Parameters:

  • name (Symbol|String)

    Metric name

  • options (Hash) (defaults to: {})

    Metric options



56
57
58
59
60
61
62
# File 'lib/librato/metrics/processor.rb', line 56

def time(name, options={})
  start = Time.now
  yield
  duration = (Time.now - start) * 1000.0 # milliseconds
  metric = {name => options.merge({:value => duration})}
  add metric
end