module Librato::Metrics::Processor
Mixin which provides common logic between {Queue} and {Aggregator} objects.
Constants
- MEASUREMENTS_PER_REQUEST
Attributes
last_submit_time[R]
per_request[R]
prefix[RW]
Public Instance Methods
client()
click to toggle source
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.
@return [Librato::Metrics::Client]
# File lib/librato/metrics/processor.rb, line 24 def client @client ||= Librato::Metrics.client end
persister()
click to toggle source
The object this MetricSet will use to persist
# File lib/librato/metrics/processor.rb, line 35 def persister @persister ||= create_persister end
submit()
click to toggle source
Persist currently queued metrics
@return Boolean
# File lib/librato/metrics/processor.rb, line 42 def submit return true if self.empty? options = {per_request: @per_request} if persister.persist(self.client, self.queued, options) @last_submit_time = Time.now clear and return true end false rescue ClientError # clean up if we hit exceptions if asked to clear if @clear_on_failure raise end
time(name, options={}) { || ... }
click to toggle source
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.
@example Queue
API request response time
queue.time :api_request_time do # API request.. end
@example Queue
API request response time w/ source
queue.time :api_request_time, source: 'app1' do # API request.. end
@param [Symbol|String] name Metric name @param [Hash] options Metric options
# File lib/librato/metrics/processor.rb, line 74 def time(name, options={}) start = Time.now yield.tap do duration = (Time.now - start) * 1000.0 # milliseconds metric = {name => options.merge({value: duration})} add metric end