Class: ATSD::SeriesService

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from ATSD::BaseService

Class Method Details

.post_payload(config, payload) ⇒ Faraday::Response

Post json

Parameters:

  • config (Hash)
    • Hash containing url, login and password keys, e.g. => “www.example.com:8088/api/v1”, :login => “login”, :password => “password”

  • payload (String)

    Body - ready to be parsed by ATSD server

Returns:

  • (Faraday::Response)

Raises:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/atsd/services/series_service.rb', line 73

def self.post_payload(config, payload)
  url = config[:url]
  , password = config[:login], config[:password]

  @connection = Faraday.new url do |builder|
    builder.headers['User-Agent'] = "ATSD Ruby Client v#{VERSION}"
    builder.basic_auth , password
    builder.request :json

    builder.response :errors_handler
    builder.response :json, :content_type => 'application/json'

    builder.adapter Faraday.default_adapter
  end
  response = @connection.post do |req|
    req.body = payload
  end
  response
end

Instance Method Details

#csv_insert(entity, data, tags = {}) ⇒ true

Series CSV: Insert

Parameters:

  • entity (String, Entity)
  • data (String)

    Payload - CSV containing time column and one or multiple metric columns.

    • Separator must be comma.

    • Time must be specified in Unix milliseconds.

    • Time column must be first, name of the time column could be arbitrary.

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

    tag=value hash

Returns:

  • (true)

Raises:



63
64
65
66
# File 'lib/atsd/services/series_service.rb', line 63

def csv_insert(entity, data, tags = {})
  entity = entity.name if entity.is_a? Entity
  @client.series_csv_insert(entity, data, tags)
end

#insert(series) ⇒ self

Insert time series.

Parameters:

Returns:

  • (self)

Raises:



42
43
44
45
46
47
48
49
50
51
# File 'lib/atsd/services/series_service.rb', line 42

def insert(series)
  series = Utils.ensure_array(series).map do |s|
    if s.is_a? Hash
      s = Series.new(s)
    end
    s.to_request_hash
  end
  @client.series_insert series
  self
end

#query(entity, metric, start_date, end_date, options = {}) ⇒ SeriesQuery

Create query builder for series.

Parameters:

  • entity (String, Entity)
  • metric (String, Metric)
  • start_date (String)
  • end_date (String)
  • options (Hash) (defaults to: {})

    other query parameters

Returns:



17
18
19
20
21
22
23
24
# File 'lib/atsd/services/series_service.rb', line 17

def query(entity, metric, start_date, end_date, options = {})
  query = SeriesQuery.new @client
  entity = entity.name if entity.is_a? Entity
  metric = metric.name if metric.is_a? Metric
  options.merge! entity: entity, metric: metric, start_date: start_date, end_date: end_date
  options.each { |option, value| query[option] = value }
  query
end

#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.

Parameters:

  • format. (String)

    Supported formats are csv and json

  • entity (String)
  • metric (String)
  • parameters (Hash) (defaults to: {})

    other query parameters

Returns:

  • (Array<Hash>)

    time series



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

def url_query(format, entity, metric, parameters={})
  @client.series_url_query(format, entity, metric, parameters)
end