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/collect.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: AgentInfoMissing, Collect, CredentialsMissing, MetricsError, NoMetricsQueued, Queue, Simple

Constant Summary collapse

TYPES =
[:counter, :gauge]
VERSION =
"0.4.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

Get data points for the last hour

data = Librato::Metrics.fetch :start_time => Time.now-3600

Get 15 min data points from two hours to an hour ago

data = Librato::Metrics.fetch :start_time => Time.now-7200,
                              :end_time => Time.now-3600,
                              :resolution => 900

Parameters:

  • metric (Symbol|String)

    Metric name

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

    Query options



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/librato/metrics.rb', line 62

def self.fetch(metric, options={})
  query = options.dup
  if query[:start_time].respond_to?(:year)
    query[:start_time] = query[:start_time].to_i
  end
  if query[:end_time].respond_to?(:year)
    query[:end_time] = query[:end_time].to_i
  end
  unless query.empty?
    query[:resolution] ||= 1
  end
  response = connection.get(:path => "v1/metrics/#{metric}",
                            :query => query, :expects => 200)
  parsed = MultiJson.decode(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: {})


89
90
91
92
93
94
95
# File 'lib/librato/metrics.rb', line 89

def self.list(options={})
  query = {}
  query[:name] = options[:name] if options[:name]
  offset = 0
  path = "v1/metrics"
  Collect.paginated_metrics connection, path, query
end