Class: ATSD::Client
- Inherits:
-
Object
- Object
- ATSD::Client
- Defined in:
- lib/atsd/client.rb
Overview
HTTP(S) Client for Axibase Time Series Database. Implements all REST methods of the API in a straightforward manner.
Instance Attribute Summary collapse
-
#connection ⇒ Faraday::Connection
readonly
Faraday connection object.
-
#logger ⇒ Logger
readonly
Logger to use.
Instance Method Summary collapse
-
#alerts_delete(actions) ⇒ true
Delete alerts.
-
#alerts_history_query(queries = nil) ⇒ Array<Hash>
Alerts history query.
-
#alerts_query(queries = nil) ⇒ Array<Hash>
Query alerts.
-
#alerts_update(actions) ⇒ true
(De-)acknowledge alerts.
-
#entities_create_or_replace(entity, body) ⇒ true
Create or replace entity.
-
#entities_delete(entity) ⇒ true
Delete entity.
-
#entities_entity_groups(entity, parameters = {}) ⇒ Array
Entity groups entity.
-
#entities_get(entity) ⇒ Hash
Entity details.
-
#entities_list(parameters = {}) ⇒ Array<Hash>
List of entities.
-
#entities_metrics(entity, parameters = {}) ⇒ Array
Metrics for entity.
-
#entities_property_types(entity, parameters = {}) ⇒ Array
Property types for entity.
-
#entities_update(entity, body) ⇒ true
Update entity.
-
#entity_groups_add_entities(entity_group, entities, parameters = {}) ⇒ true
Add entities to entity group.
-
#entity_groups_create_or_replace(entity_group, body) ⇒ true
Create or replace entity group.
-
#entity_groups_delete(entity_group) ⇒ true
Delete entity group.
-
#entity_groups_delete_entities(entity_group, entities) ⇒ true
Delete entities in entity group.
-
#entity_groups_get(entity_group) ⇒ Hash
Entity group info.
-
#entity_groups_get_entities(entity_group, parameters = {}) ⇒ Array
List entity group entities.
-
#entity_groups_list(parameters = {}) ⇒ Array
Entity groups list.
-
#entity_groups_replace_entities(entity_group, entities, parameters = {}) ⇒ true
Replace entities in entity group.
-
#entity_groups_update(entity_group, body) ⇒ true
Update entity group.
-
#initialize(options, &block) ⇒ Client
constructor
See ATSD.new.
-
#messages_insert(messages) ⇒ Object
Insert messages.
-
#messages_query(queries = nil) ⇒ Array<Hash>
Query messages.
-
#messages_stat_query(parameters = {}) ⇒ Array<Hash>
Statistics query.
-
#metrics_create_or_replace(metric, body) ⇒ true
Create a metric with specified properties and tags or replace an existing metric.
-
#metrics_delete(metric) ⇒ true
Delete the metric.
-
#metrics_get(metric) ⇒ Hash
Displays metric properties and its tags.
-
#metrics_list(parameters = {}) ⇒ Array<Hash>
Metrics list.
-
#metrics_series(metric, parameters = {}) ⇒ Array
Returns a list of series for the metric.
-
#metrics_update(metric, body) ⇒ true
Update specified properties and tags for the given metric.
-
#properties_delete(properties) ⇒ Object
Delete an array of properties for entity, type, and optionally for specified keys.
-
#properties_for_entity(entity) ⇒ Array<Hash>
Returns array of property types for the entity.
-
#properties_for_entity_and_type(entity, type) ⇒ Array<Hash>
Returns properties for entity and type.
-
#properties_insert(properties) ⇒ Object
Insert properties.
-
#properties_query(queries = nil) ⇒ Array<Hash>
Query properties.
-
#series_csv_insert(entity, data, tags = {}) ⇒ true
Series CSV: Insert.
-
#series_insert(series) ⇒ Object
Insert time series.
-
#series_query(queries) ⇒ Array<Hash>
Query time series.
-
#series_url_query(format, entity, metric, parameters = {}) ⇒ Array<Hash>
Retrieve series values for the specified entity, metric, and optional series tags in CSV and JSON format.
Constructor Details
#initialize(options, &block) ⇒ Client
See ATSD.new
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/atsd/client.rb', line 18 def initialize(, &block) = .symbolize_keys login, password = extract_basic_auth() @logger = extract_logger() url = .delete(:url) @connection = Faraday.new url, do |builder| builder.headers['User-Agent'] = "ATSD Ruby Client v#{VERSION}" builder.basic_auth login, password builder.request :json builder.response :errors_handler builder.response :json, :content_type => 'application/json' builder.response :logger, @logger, :bodies => true if @logger builder.adapter Faraday.default_adapter end if block_given? block.arity > 0 ? yield(@connection.builder) : @connection.builder.instance_eval(&block) end true end |
Instance Attribute Details
#connection ⇒ Faraday::Connection (readonly)
Returns faraday connection object.
12 13 14 |
# File 'lib/atsd/client.rb', line 12 def connection @connection end |
#logger ⇒ Logger (readonly)
Returns logger to use.
15 16 17 |
# File 'lib/atsd/client.rb', line 15 def logger @logger end |
Instance Method Details
#alerts_delete(actions) ⇒ true
Delete alerts
217 218 219 220 |
# File 'lib/atsd/client.rb', line 217 def alerts_delete(actions) @connection.post 'alerts/delete', Utils.ensure_array(actions) true end |
#alerts_history_query(queries = nil) ⇒ Array<Hash>
Alerts history query
228 229 230 231 |
# File 'lib/atsd/client.rb', line 228 def alerts_history_query(queries = nil) response = @connection.post 'alerts/history/query', Utils.ensure_array(queries) response.body end |
#alerts_query(queries = nil) ⇒ Array<Hash>
Query alerts
195 196 197 198 |
# File 'lib/atsd/client.rb', line 195 def alerts_query(queries = nil) response = @connection.post 'alerts/query', Utils.ensure_array(queries) response.body end |
#alerts_update(actions) ⇒ true
(De-)acknowledge alerts
206 207 208 209 |
# File 'lib/atsd/client.rb', line 206 def alerts_update(actions) @connection.post 'alerts/update', Utils.ensure_array(actions) true end |
#entities_create_or_replace(entity, body) ⇒ true
Create or replace entity.
340 341 342 343 |
# File 'lib/atsd/client.rb', line 340 def entities_create_or_replace(entity, body) @connection.put "entities/#{CGI.escape(entity)}", body true end |
#entities_delete(entity) ⇒ true
Delete entity.
363 364 365 366 |
# File 'lib/atsd/client.rb', line 363 def entities_delete(entity) @connection.delete "entities/#{CGI.escape(entity)}" true end |
#entities_entity_groups(entity, parameters = {}) ⇒ Array
Entity groups entity.
374 375 376 377 |
# File 'lib/atsd/client.rb', line 374 def entities_entity_groups(entity, parameters = {}) response = @connection.get "entities/#{CGI.escape(entity)}/groups", parameters response.body end |
#entities_get(entity) ⇒ Hash
Entity details
328 329 330 331 |
# File 'lib/atsd/client.rb', line 328 def entities_get(entity) response = @connection.get "entities/#{CGI.escape(entity)}" response.body end |
#entities_list(parameters = {}) ⇒ Array<Hash>
List of entities
317 318 319 320 |
# File 'lib/atsd/client.rb', line 317 def entities_list(parameters = {}) response = @connection.get 'entities', parameters response.body end |
#entities_metrics(entity, parameters = {}) ⇒ Array
Metrics for entity
398 399 400 401 |
# File 'lib/atsd/client.rb', line 398 def entities_metrics(entity, parameters = {}) response = @connection.get "entities/#{CGI.escape(entity)}/metrics", parameters response.body end |
#entities_property_types(entity, parameters = {}) ⇒ Array
Property types for entity
386 387 388 389 |
# File 'lib/atsd/client.rb', line 386 def entities_property_types(entity, parameters = {}) response = @connection.get "entities/#{CGI.escape(entity)}/property-types", parameters response.body end |
#entities_update(entity, body) ⇒ true
Update entity.
352 353 354 355 |
# File 'lib/atsd/client.rb', line 352 def entities_update(entity, body) @connection.patch "entities/#{CGI.escape(entity)}", body true end |
#entity_groups_add_entities(entity_group, entities, parameters = {}) ⇒ true
Add entities to entity group.
480 481 482 483 484 485 486 487 |
# File 'lib/atsd/client.rb', line 480 def entity_groups_add_entities(entity_group, entities, parameters = {}) @connection.patch "entity-groups/#{CGI.escape(entity_group)}/entities", [ parameters.merge(:action => 'add', :createEntities => true, :entities => entities) ] true end |
#entity_groups_create_or_replace(entity_group, body) ⇒ true
Create or replace entity group.
432 433 434 435 |
# File 'lib/atsd/client.rb', line 432 def entity_groups_create_or_replace(entity_group, body) @connection.put "entity-groups/#{CGI.escape(entity_group)}", body true end |
#entity_groups_delete(entity_group) ⇒ true
Delete entity group.
455 456 457 458 |
# File 'lib/atsd/client.rb', line 455 def entity_groups_delete(entity_group) @connection.delete "entity-groups/#{CGI.escape(entity_group)}" true end |
#entity_groups_delete_entities(entity_group, entities) ⇒ true
Delete entities in entity group.
509 510 511 512 513 514 |
# File 'lib/atsd/client.rb', line 509 def entity_groups_delete_entities(entity_group, entities) @connection.patch "entity-groups/#{CGI.escape(entity_group)}/entities", [ {:action => 'delete', :entities => entities} ] true end |
#entity_groups_get(entity_group) ⇒ Hash
Entity group info
420 421 422 423 |
# File 'lib/atsd/client.rb', line 420 def entity_groups_get(entity_group) response = @connection.get "entity-groups/#{CGI.escape(entity_group)}" response.body end |
#entity_groups_get_entities(entity_group, parameters = {}) ⇒ Array
List entity group entities.
467 468 469 470 |
# File 'lib/atsd/client.rb', line 467 def entity_groups_get_entities(entity_group, parameters = {}) response = @connection.get "entity-groups/#{CGI.escape(entity_group)}/entities", parameters response.body end |
#entity_groups_list(parameters = {}) ⇒ Array
Entity groups list.
409 410 411 412 |
# File 'lib/atsd/client.rb', line 409 def entity_groups_list(parameters = {}) response = @connection.get 'entity-groups', parameters response.body end |
#entity_groups_replace_entities(entity_group, entities, parameters = {}) ⇒ true
Replace entities in entity group.
497 498 499 500 |
# File 'lib/atsd/client.rb', line 497 def entity_groups_replace_entities(entity_group, entities, parameters = {}) @connection.put "entity-groups/#{CGI.escape(entity_group)}/entities", entities true end |
#entity_groups_update(entity_group, body) ⇒ true
Update entity group.
444 445 446 447 |
# File 'lib/atsd/client.rb', line 444 def entity_groups_update(entity_group, body) @connection.patch "entity-groups/#{CGI.escape(entity_group)}", body true end |
#messages_insert(messages) ⇒ Object
Insert messages
117 118 119 120 |
# File 'lib/atsd/client.rb', line 117 def () @connection.post 'messages/insert', Utils.ensure_array() true end |
#messages_query(queries = nil) ⇒ Array<Hash>
Query messages
106 107 108 109 |
# File 'lib/atsd/client.rb', line 106 def (queries = nil) response = @connection.post 'messages/query', Utils.ensure_array(queries) response.body end |
#messages_stat_query(parameters = {}) ⇒ Array<Hash>
Statistics query
128 129 130 131 132 |
# File 'lib/atsd/client.rb', line 128 def (parameters = {}) print parameters response = @connection.post 'messages/stats/query', Utils.ensure_array(parameters) response.body end |
#metrics_create_or_replace(metric, body) ⇒ true
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.
266 267 268 269 |
# File 'lib/atsd/client.rb', line 266 def metrics_create_or_replace(metric, body) @connection.put "metrics/#{CGI.escape(metric)}", body true end |
#metrics_delete(metric) ⇒ true
Delete the metric. Data collected for the metric will be removed asynchronously in the background.
293 294 295 296 |
# File 'lib/atsd/client.rb', line 293 def metrics_delete(metric) @connection.delete "metrics/#{CGI.escape(metric)}" true end |
#metrics_get(metric) ⇒ Hash
Displays metric properties and its tags.
250 251 252 253 |
# File 'lib/atsd/client.rb', line 250 def metrics_get(metric) response = @connection.get "metrics/#{CGI.escape(metric)}" response.body end |
#metrics_list(parameters = {}) ⇒ Array<Hash>
Metrics list.
239 240 241 242 |
# File 'lib/atsd/client.rb', line 239 def metrics_list(parameters = {}) response = @connection.get 'metrics', parameters response.body end |
#metrics_series(metric, parameters = {}) ⇒ Array
Returns a list of series for the metric. Each series is identified with metric name, entity name, and optional series tags.
306 307 308 309 |
# File 'lib/atsd/client.rb', line 306 def metrics_series(metric, parameters = {}) response = @connection.get "metrics/#{CGI.escape(metric)}/series", parameters response.body end |
#metrics_update(metric, body) ⇒ true
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.
281 282 283 284 |
# File 'lib/atsd/client.rb', line 281 def metrics_update(metric, body) @connection.patch "metrics/#{CGI.escape(metric)}", body true end |
#properties_delete(properties) ⇒ Object
Delete an array of properties for entity, type, and optionally for specified keys
185 186 187 |
# File 'lib/atsd/client.rb', line 185 def properties_delete(properties) @connection.post 'properties/delete', Utils.ensure_array(properties) end |
#properties_for_entity(entity) ⇒ Array<Hash>
Returns array of property types for the entity.
163 164 165 166 |
# File 'lib/atsd/client.rb', line 163 def properties_for_entity(entity) response = @connection.get "properties/#{CGI.escape(entity)}/types" response.body end |
#properties_for_entity_and_type(entity, type) ⇒ Array<Hash>
Returns properties for entity and type.
152 153 154 155 |
# File 'lib/atsd/client.rb', line 152 def properties_for_entity_and_type(entity, type) response = @connection.get "properties/#{CGI.escape(entity)}/types/#{CGI.escape(type)}" response.body end |
#properties_insert(properties) ⇒ Object
Insert properties
174 175 176 177 |
# File 'lib/atsd/client.rb', line 174 def properties_insert(properties) @connection.post 'properties/insert', Utils.ensure_array(properties) true end |
#properties_query(queries = nil) ⇒ Array<Hash>
Query properties
140 141 142 143 |
# File 'lib/atsd/client.rb', line 140 def properties_query(queries = nil) response = @connection.post 'properties/query', Utils.ensure_array(queries) response.body end |
#series_csv_insert(entity, data, tags = {}) ⇒ true
Series CSV: Insert
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/atsd/client.rb', line 89 def series_csv_insert(entity, data, = {}) request = @connection.build_request(:post) do |req| req.url("series/csv/#{CGI.escape(entity)}", ) req.headers["Content-Type"] = 'text/csv' req.body = data end @connection.builder.build_response(@connection, request) true end |
#series_insert(series) ⇒ Object
Insert time series
73 74 75 76 |
# File 'lib/atsd/client.rb', line 73 def series_insert(series) @connection.post 'series/insert', Utils.ensure_array(series) true end |
#series_query(queries) ⇒ Array<Hash>
Query time series
47 48 49 50 |
# File 'lib/atsd/client.rb', line 47 def series_query(queries) response = @connection.post 'series/query', Utils.ensure_array(queries) response.body end |
#series_url_query(format, entity, metric, parameters = {}) ⇒ Array<Hash>
Retrieve series values for the specified entity, metric, and optional series tags in CSV and JSON format
61 62 63 64 65 |
# File 'lib/atsd/client.rb', line 61 def series_url_query(format, entity, metric, parameters ={}) url = "series/#{CGI.escape(format)}/#{CGI.escape(entity)}/#{CGI.escape(metric)}?" response = @connection.get url, parameters response.body end |