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:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/atsd/services/series_service.rb', line 62

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:



52
53
54
55
# File 'lib/atsd/services/series_service.rb', line 52

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:



31
32
33
34
35
36
37
38
39
40
# File 'lib/atsd/services/series_service.rb', line 31

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_time, end_time, options = {}) ⇒ SeriesQuery

Create query builder for series.

Parameters:

  • entity (String, Entity)
  • metric (String, Metric)
  • start_time (Fixnum)
  • end_time (Fixnum)
  • 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_time, end_time, 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_time: start_time, end_time: end_time
  options.each { |option, value| query[option] = value }
  query
end