Class: ATSD::EntitiesService

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

Overview

Entities service

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(entity) ⇒ self

Note:

If only a subset of fields is provided for an existing entity, the remaining properties will be set to default values and tags will be deleted.

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

Parameters:

Returns:

  • (self)

Raises:



49
50
51
52
53
54
55
# File 'lib/atsd/services/entities_service.rb', line 49

def create_or_replace(entity)
  entity = Entity.new(entity) if entity.is_a? Hash
  name = name_for_entity entity
  raise ArgumentError unless name
  @client.entities_create_or_replace(name, entity.to_request_hash)
  self
end

#delete(entity) ⇒ self

Delete the entity. Delete the entity from any Entity Groups that it belongs to. Data collected by the entity will be removed asynchronously in the background.

Parameters:

  • entity (Hash, Entity, String)

    entity or name

Returns:

  • (self)

Raises:



77
78
79
80
# File 'lib/atsd/services/entities_service.rb', line 77

def delete(entity)
  @client.entities_delete(name_for_entity entity)
  self
end

#entity_groups(entity) ⇒ Array<EntityGroup>

Returns an array of Entity Groups to which the entity belongs. Entity-group tags are included in the reponse.

Parameters:

  • entity (Hash, Entity, String)

    entity or name

Returns:

Raises:



88
89
90
91
# File 'lib/atsd/services/entities_service.rb', line 88

def entity_groups(entity)
  result = @client.entities_entity_groups(name_for_entity entity)
  result.map { |json| EntityGroup.new json }
end

#get(entity) ⇒ Entity

Displays entity properties and all tags.

Parameters:

Returns:

Raises:



34
35
36
# File 'lib/atsd/services/entities_service.rb', line 34

def get(entity)
  Entity.new(@client.entities_get(name_for_entity entity))
end

#list(options = {}) ⇒ Array<Entity>

Entities list

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :active (Boolean)

    Filter entities by last insert time. If ‘active = true`, only entities with positive `last_insert_time` are included in the response

  • :expression (String)

    Use ‘name` variable for entity name. Use `*` placeholder in `like` expresions

  • :tags (Array<String>)

    Specify entity tags to be included in the response

  • :limit (Integer)

    Limit response to first N entities, ordered by name.

Returns:

Raises:



22
23
24
25
26
27
# File 'lib/atsd/services/entities_service.rb', line 22

def list(options = {})
  options = options.camelize_keys
  @client.entities_list(options).map do |json|
    Entity.new json
  end
end

#metrics(entity, options = {}) ⇒ Array<Metric>

Returns a list of metrics collected by the entity. The list is based on memory cache which is rebuilt on ATSD restart.

Parameters:

  • entity (String, Hash, Entity)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :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<String>)

    Specify metric tags to be included in the response

  • :limit (Integer)

    Limit response to first N metrics, ordered by name.

Returns:

Raises:



119
120
121
122
123
124
# File 'lib/atsd/services/entities_service.rb', line 119

def metrics(entity, options = {})
  options = options.camelize_keys
  @client.entities_metrics(name_for_entity(entity), options).map do |json|
    Metric.new json
  end
end

#property_types(entity, start_date = nil) ⇒ Array<String>

Returns an array of property types for the entity.

Parameters:

  • entity (String, Hash, Entity)
  • start_date (Integer, Time) (defaults to: nil)

    Return only property types that have been collected after the specified time.

Returns:

  • (Array<String>)

Raises:



100
101
102
103
104
# File 'lib/atsd/services/entities_service.rb', line 100

def property_types(entity, start_date = nil)
  start_date = start_date.iso8601 if start_date.is_a? Time
  params = start_date ? { :start_date => start_date } : {}
  @client.entities_property_types(name_for_entity(entity), params)
end

#update(entity) ⇒ self

Note:

updates specified properties and tags for an existing entity. Properties and tags that are not specified are left unchanged.

Update specified properties and tags for the given entity.

Parameters:

Returns:

  • (self)

Raises:



64
65
66
67
68
# File 'lib/atsd/services/entities_service.rb', line 64

def update(entity)
  entity = Entity.new(entity) if entity.is_a? Hash
  @client.entities_update(name_for_entity(entity), entity.to_request_hash)
  self
end