Class: ATSD::MetricsService

Inherits:
BaseService show all
Defined in:
lib/atsd/services/metrics_service.rb

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from ATSD::BaseService

Instance Method Details

#create_or_replace(metric) ⇒ self

Note:

If only a subset of fields is provided for an existing metric, the remaining properties and tags will be deleted.

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

Parameters:

Returns:

  • (self)

Raises:



47
48
49
50
51
52
# 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) ⇒ self

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

Parameters:

Returns:

  • (self)

Raises:



74
75
76
77
# File 'lib/atsd/services/metrics_service.rb', line 74

def delete(metric)
  @client.metrics_delete(name_for_metric(metric))
  self
end

#entity_and_tags(metric, entity = nil) ⇒ Array<Entity>

Returns a list of unique series tags for the metric. The list is based on data stored on disk for the last 24 hours.

Parameters:

Returns:

Raises:



86
87
88
89
90
91
92
# File 'lib/atsd/services/metrics_service.rb', line 86

def entity_and_tags(metric, entity = nil)
  metric = name_for_metric(metric)
  params = {}
  params[:entity] = name_for_entity(entity) if entity
  result = @client.metrics_entity_and_tags(metric, params)
  result.map { |json| Entity.new json }
end

#get(metric) ⇒ Array<Metric>

Displays metric properties and its tags.

Parameters:

  • metric (String)

Returns:

Raises:



33
34
35
# File 'lib/atsd/services/metrics_service.rb', line 33

def get(metric)
  Metric.new(@client.metrics_get(name_for_metric metric))
end

#list(parameters = {}) ⇒ Array<Metric>

Metrics list.

Parameters:

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

    a customizable set of options

Options Hash (parameters):

  • :expression (String)

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

  • :active (Boolean)

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

  • :tags (Array)

    Specify metric tags to be included in the response

  • :limit (Integer)

    Limit response to first N metrics, ordered by name.

Returns:

Raises:



21
22
23
24
25
26
# 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

#update(metric) ⇒ self

Note:

Properties and tags that are not specified are left unchanged.

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

Parameters:

Returns:

  • (self)

Raises:



62
63
64
65
66
# 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