module Librato::Metrics
Metrics
provides a simple wrapper for the Metrics
web API with a number of added conveniences for common use cases.
See the {file:README.md README} for more information and examples.
@example Simple use case
Librato::Metrics.authenticate 'email', 'api_key' # list current metrics Librato::Metrics.metrics # submit a metric immediately Librato::Metrics.submit foo: 12712 # fetch the last 10 values of foo Librato::Metrics.get_measurements :foo, count: 10
@example Queuing metrics for submission
queue = Librato::Metrics::Queue.new # queue some metrics queue.add foo: 12312 queue.add bar: 45678 # send the metrics queue.submit
@example Using a Client
object
client = Librato::Metrics::Client.new client.authenticate 'email', 'api_key' # list client's metrics client.metrics # create an associated queue queue = client.new_queue # queue up some metrics and submit queue.add foo: 12345 queue.add bar: 45678 queue.submit
@note Most of the methods you can call directly on Librato::Metrics
are
delegated to {Client} and are documented there.
Constants
- MIN_MEASURE_TIME
- PLURAL_TYPES
- TYPES
- VERSION
Public Class Methods
client()
click to toggle source
The Librato::Metrics::Client
being used by module-level access.
@return [Client]
# File lib/librato/metrics.rb, line 90 def self.client @client ||= Librato::Metrics::Client.new end
Private Instance Methods
autosubmit_check()
click to toggle source
# File lib/librato/metrics/processor.rb, line 108 def autosubmit_check if @autosubmit_interval last = @last_submit_time || @create_time self.submit if (Time.now - last).to_i >= @autosubmit_interval end end
create_persister()
click to toggle source
# File lib/librato/metrics/processor.rb, line 86 def create_persister type = self.client.persistence.to_s.capitalize Librato::Metrics::Persistence.const_get(type).new end
epoch_time()
click to toggle source
# File lib/librato/metrics/processor.rb, line 91 def epoch_time Time.now.to_i end
setup_common_options(options)
click to toggle source
# File lib/librato/metrics/processor.rb, line 95 def setup_common_options(options) validate_parameters(options) @autosubmit_interval = options[:autosubmit_interval] @client = options[:client] || Librato::Metrics.client @per_request = options[:per_request] || MEASUREMENTS_PER_REQUEST @source = options[:source] @tags = options.fetch(:tags, {}) @time = (options[:time] && options[:time].to_i || options[:measure_time] && options[:measure_time].to_i) @create_time = Time.now @clear_on_failure = options[:clear_failures] || false @prefix = options[:prefix] end
validate_parameters(options)
click to toggle source
# File lib/librato/metrics/processor.rb, line 115 def validate_parameters(options) invalid_combinations = [ [:source, :tags], ] opts = options.keys.to_set invalid_combinations.each do |combo| if combo.to_set.subset?(opts) raise InvalidParameters, "#{combo} cannot be simultaneously set" end end end