Module: Librato::Metrics

Extended by:
SingleForwardable
Defined in:
lib/librato/metrics.rb,
lib/librato/metrics/queue.rb,
lib/librato/metrics/errors.rb,
lib/librato/metrics/simple.rb,
lib/librato/metrics/version.rb,
lib/librato/metrics/persistence/test.rb,
lib/librato/metrics/persistence/direct.rb

Overview

Metrics provides a simple wrapper for the Metrics web API. Some of the methods Metrics provides will be documented below. Others are delegated to Simple and will be documented there.

Defined Under Namespace

Modules: Persistence Classes: CredentialsMissing, MetricsError, NoMetricsQueued, Queue, Simple

Constant Summary collapse

TYPES =
[:counter, :gauge]
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.fetch(metric, options = {}) ⇒ Object

Query metric data

A full list of query parameters can be found in the API documentation: http://dev.librato.com/v1/get/gauges/:name

Examples:

Get attributes for a metric

attrs = Librato::Metrics.fetch :temperature

Get 20 most recent data points for metric

data = Librato::Metrics.fetch :temperature, :count => 20

Get 20 most recent data points for a specific source

data = Librato::Metrics.fetch :temperature, :count => 20,
                               :source => 'app1'

Get the 20 most recent 15 minute data point rollups

data = Librato::Metrics.fetch :temperature, :count => 20,
                              :resolution => 900

Parameters:

  • metric (Symbol|String)

    Metric name

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

    Query options



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/librato/metrics.rb', line 53

def self.fetch(metric, options={})
  resolution = options.delete(:resolution) || 1
  count = options.delete(:count)
  query = {}
  if count
    query.merge!({:count => count, :resolution => resolution})
  end
  query.merge!(options)
  # TODO: look up type when not specified.
  type = options.delete(:type) || 'gauge'
  response = connection.get(:path => "v1/#{type}s/#{metric}.json",
                            :query => query, :expects => 200)
  parsed = JSON.parse(response.body)
  # TODO: pagination support
  query.empty? ? parsed : parsed["measurements"]
end

.list(options = {}) ⇒ Object

List currently existing metrics

Examples:

List all metrics

Librato::Metrics.list

List metrics with ‘foo’ in the name

Librato::Metrics.list :name => 'foo'

Parameters:

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


79
80
81
82
83
84
85
86
# File 'lib/librato/metrics.rb', line 79

def self.list(options={})
  query = {}
  query[:name] = options[:name] if options[:name]
  response = connection.get(:path => 'v1/metrics.json',
                            :query => query, :expects => 200)
  # TODO: pagination support
  JSON.parse(response.body)["metrics"]
end