Class: ATSD::EntitiesService
- Inherits:
-
BaseService
- Object
- BaseService
- ATSD::EntitiesService
- Defined in:
- lib/atsd/services/entities_service.rb
Overview
Entities service
Instance Method Summary collapse
-
#create_or_replace(entity) ⇒ self
Create an entity with specified properties and tags or replace an existing entity.
-
#delete(entity) ⇒ self
Delete the entity.
-
#entity_groups(entity) ⇒ Array<EntityGroup>
Returns an array of Entity Groups to which the entity belongs.
-
#get(entity) ⇒ Entity
Displays entity properties and all tags.
-
#list(options = {}) ⇒ Array<Entity>
Entities list.
-
#metrics(entity, options = {}) ⇒ Array<Metric>
Returns a list of metrics collected by the entity.
-
#property_types(entity, start_date = nil) ⇒ Array<String>
Returns an array of property types for the entity.
-
#update(entity) ⇒ self
Update specified properties and tags for the given entity.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from ATSD::BaseService
Instance Method Details
#create_or_replace(entity) ⇒ self
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.
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.
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.
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.
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
22 23 24 25 26 27 |
# File 'lib/atsd/services/entities_service.rb', line 22 def list( = {}) = .camelize_keys @client.entities_list().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.
119 120 121 122 123 124 |
# File 'lib/atsd/services/entities_service.rb', line 119 def metrics(entity, = {}) = .camelize_keys @client.entities_metrics(name_for_entity(entity), ).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.
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
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.
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 |