Class: Opower::TimeSeries::Query::MetricQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/time_series/query.rb

Overview

Wrapper class for each query made against a separate metric.

Instance Method Summary collapse

Constructor Details

#initialize(metric) ⇒ MetricQuery

Initializes a wrapper object that represent a single metric that will be queried against in OpenTSDB.

Parameters:

  • metric (Hash)

    a Hash representing a query against OpenTSDB



91
92
93
94
95
96
97
98
# File 'lib/time_series/query.rb', line 91

def initialize(metric)
  @metric = metric.fetch(:metric)
  @tags = metric.fetch(:tags, {})
  @aggregator = metric.fetch(:aggregator, 'sum')
  @rate = metric.fetch(:rate, false)

  initialize_downsample(metric)
end

Instance Method Details

#to_sString

Builds the query string representation of this MetricQuery object.

Returns:

  • (String)

    the URL query string that will be used for this metric query.



103
104
105
106
107
108
109
# File 'lib/time_series/query.rb', line 103

def to_s
  str = "#{@aggregator}:"
  str << "#{@period}-#{@function}:" if @downsample
  str << 'rate:' if @rate
  str << "#{@metric}{#{build_tags}}"
  str
end