Class: Librato::Metrics::Persistence::Direct

Inherits:
Object
  • Object
show all
Defined in:
lib/librato/metrics/persistence/direct.rb

Instance Method Summary collapse

Instance Method Details

#persist(client, queued, options = {}) ⇒ Object

Persist the queued metrics directly to the Metrics web API.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/librato/metrics/persistence/direct.rb', line 11

def persist(client, queued, options={})
  per_request = options[:per_request]
  if per_request
    requests = chunk_queued(queued, per_request)
  else
    requests = [queued]
  end
  requests.each do |request|
    resource =
      if queued[:gauges] || queued[:counters]
        "metrics"
      else
        "measurements"
      end
    payload = SmartJSON.write(request)
    # expects 200
    client.connection.post(resource, payload)
  end
end