class Dogapi::V1::MetricService

Event-specific client affording more granular control than the simple Dogapi::Client

Constants

API_VERSION

Public Instance Methods

flush_buffer() click to toggle source
   # File lib/dogapi/v1/metric.rb
40 def flush_buffer()
41   payload = @buffer
42   @buffer = nil
43   self.upload(payload)
44 end
get(query, from, to) click to toggle source
   # File lib/dogapi/v1/metric.rb
13 def get(query, from, to)
14   extra_params = {
15     from: from.to_i,
16     to: to.to_i,
17     query: query
18   }
19   request(Net::HTTP::Get, '/api/' + API_VERSION + '/query', extra_params, nil, false)
20 end
get_active_metrics(from) click to toggle source
   # File lib/dogapi/v1/metric.rb
89 def get_active_metrics(from)
90   params = {
91     from: from.to_i
92   }
93 
94   request(Net::HTTP::Get, '/api/' + API_VERSION + '/metrics', params, nil, false)
95 end
make_metric_payload(metric, points, scope, options) click to toggle source
   # File lib/dogapi/v1/metric.rb
62 def make_metric_payload(metric, points, scope, options)
63   begin
64     typ = options[:type] || 'gauge'
65 
66     if typ != 'gauge' && typ != 'counter' && typ != 'count' && typ != 'rate'
67       raise ArgumentError, 'metric type must be gauge or counter or count or rate'
68     end
69 
70     metric_payload = {
71       :metric => metric,
72       :points => points,
73       :type => typ,
74       :host => scope.host,
75       :device => scope.device
76     }
77 
78     # Add tags if there are any
79     if not options[:tags].nil?
80       metric_payload[:tags] = options[:tags]
81     end
82 
83     return metric_payload
84   rescue Exception => e
85     suppress_error_if_silent e
86   end
87 end
submit(*args) click to toggle source
   # File lib/dogapi/v1/metric.rb
46 def submit(*args)
47   if @buffer
48     submit_to_buffer(*args)
49   else
50     submit_to_api(*args)
51   end
52 end
submit_to_api(metric, points, scope, options= {}) click to toggle source
   # File lib/dogapi/v1/metric.rb
29 def submit_to_api(metric, points, scope, options= {})
30   payload = self.make_metric_payload(metric, points, scope, options)
31   self.upload([payload])
32 end
submit_to_buffer(metric, points, scope, options= {}) click to toggle source
   # File lib/dogapi/v1/metric.rb
34 def submit_to_buffer(metric, points, scope, options= {})
35   payload = self.make_metric_payload(metric, points, scope, options)
36   @buffer << payload
37   return 200, {}
38 end
switch_to_batched() click to toggle source
   # File lib/dogapi/v1/metric.rb
54 def switch_to_batched()
55   @buffer = Array.new
56 end
switch_to_single() click to toggle source
   # File lib/dogapi/v1/metric.rb
58 def switch_to_single()
59   @buffer = nil
60 end
upload(metrics) click to toggle source
   # File lib/dogapi/v1/metric.rb
22 def upload(metrics)
23   body = {
24     :series => metrics
25   }
26   request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', nil, body, true, false)
27 end