class ATSD::MetricsService

Public Instance Methods

create_or_replace(metric) click to toggle source

Create a metric with specified properties and tags or replace an existing metric. This method creates a new metric or replaces an existing metric.

@note If only a subset of fields is provided for an existing metric,

the remaining properties and tags will be deleted.

@param [Hash, Metric, String] metric @return [self] @raise [APIError]

# File lib/atsd/services/metrics_service.rb, line 47
def create_or_replace(metric)
  metric = Metric.new(name: metric) if metric.is_a? String
  metric = Metric.new(metric) if metric.is_a? Hash
  @client.metrics_create_or_replace(metric.name, metric.to_request_hash)
  self
end
delete(metric) click to toggle source

Delete the metric. Data collected for the metric will be removed asynchronously in the background.

@param [String, Metric, Hash] metric @return [self] @raise [APIError]

# File lib/atsd/services/metrics_service.rb, line 74
def delete(metric)
  @client.metrics_delete(name_for_metric(metric))
  self
end
get(metric) click to toggle source

Displays metric properties and its tags.

@param [String] metric @return [Array<Metric>] @raise [APIError]

# File lib/atsd/services/metrics_service.rb, line 33
def get(metric)
  Metric.new(@client.metrics_get(name_for_metric metric))
end
list(parameters = {}) click to toggle source

Metrics list.

@option parameters [String] :expression

Use name variable for metric name. Use * placeholder
in like expressions

@option parameters [Boolean] :active

Filter metrics by last_insert_time. If active = true,
only metrics with positive last_insert_time are included in the response

@option parameters [Array] :tags

Specify metric tags to be included in the response

@option parameters [Integer] :limit

Limit response to first N metrics, ordered by name.

@return [Array<Metric>] @raise [APIError]

# File lib/atsd/services/metrics_service.rb, line 21
def list(parameters = {})
  parameters = parameters.camelize_keys
  @client.metrics_list(parameters).map do |json|
    Metric.new json
  end
end
series(metric, params = {}) click to toggle source

Returns a list of series for the metric. Each series is identified with metric name, entity name and optional series tags

@param [Hash, Metric, String] metric @return [Array<Series>] @raise [APIError]

# File lib/atsd/services/metrics_service.rb, line 86
def series(metric, params = {})
  result = @client.metrics_series(name_for_metric(metric), params)
  result.map { |json| Series.new json }
end
update(metric) click to toggle source

Update specified properties and tags for the given metric. This method updates specified properties and tags for an existing metric.

@note Properties and tags that are not specified are left unchanged.

@param [Hash, Metric] metric @return [self] @raise [APIError]

# File lib/atsd/services/metrics_service.rb, line 62
def update(metric)
  metric = Metric.new(metric) if metric.is_a? Hash
  @client.metrics_update(metric.name, metric.to_request_hash)
  self
end

Private Instance Methods

name_for_entity(entity) click to toggle source
# File lib/atsd/services/metrics_service.rb, line 106
def name_for_entity(entity)
  case entity
    when String
      entity
    when Hash
      entity[:name] || entity['name']
    when Entity
      entity.name? ? entity.name : nil
    else
      entity.name
  end
end
name_for_metric(metric) click to toggle source
# File lib/atsd/services/metrics_service.rb, line 93
def name_for_metric(metric)
  case metric
    when String
      metric
    when Hash
      metric[:name] || metric['name']
    when Metric
      metric.name? ? metric.name : nil
    else
      metric.name
  end
end