class DogapiDemo::V1::MetricService

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

Constants

API_VERSION

Public Instance Methods

flush_buffer() click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
62 def flush_buffer()
63   payload = @buffer
64   @buffer = nil
65   self.upload(payload)
66 end
get(query, from, to) click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
11 def get(query, from, to)
12   begin
13     params = {
14       :api_key => @api_key,
15       :application_key => @application_key,
16 
17       from: from.to_i,
18       to: to.to_i,
19       query: query
20     }
21     request(Net::HTTP::Get, '/api/' + API_VERSION + '/query', params, nil, false)
22   rescue Exception => e
23     if @silent
24       warn e
25       return -1, {}
26     else
27       raise e
28     end
29   end
30 end
make_metric_payload(metric, points, scope, options) click to toggle source
    # File lib/dogapi-demo/v1/metric.rb
 84 def make_metric_payload(metric, points, scope, options)
 85   begin
 86     typ = options[:type] || "gauge"
 87 
 88     if typ != "gauge" && typ != "counter"
 89       raise ArgumentError, "metric type must be gauge or counter"
 90     end
 91 
 92     metric_payload = {
 93       :metric => metric,
 94       :points => points,
 95       :type => typ,
 96       :host => scope.host,
 97       :device => scope.device
 98     }
 99 
100     # Add tags if there are any
101     if not options[:tags].nil?
102       metric_payload[:tags] = options[:tags]
103     end
104 
105     return metric_payload
106   rescue Exception => e
107     if @silent
108       warn e
109       return -1, {}
110     else
111       raise e
112     end
113   end
114 end
submit(*args) click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
68 def submit(*args)
69   if @buffer
70     submit_to_buffer(*args)
71   else
72     submit_to_api(*args)
73   end
74 end
submit_to_api(metric, points, scope, options = {}) click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
51 def submit_to_api(metric, points, scope, options = {})
52   payload = self.make_metric_payload(metric, points, scope, options)
53   self.upload([payload])
54 end
submit_to_buffer(metric, points, scope, options = {}) click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
56 def submit_to_buffer(metric, points, scope, options = {})
57   payload = self.make_metric_payload(metric, points, scope, options)
58   @buffer << payload
59   return 200, {}
60 end
switch_to_batched() click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
76 def switch_to_batched()
77   @buffer = Array.new
78 end
switch_to_single() click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
80 def switch_to_single()
81   @buffer = nil
82 end
upload(metrics) click to toggle source
   # File lib/dogapi-demo/v1/metric.rb
32 def upload(metrics)
33   begin
34     params = {
35       :api_key => @api_key
36     }
37     body = {
38       :series => metrics
39     }
40     request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', params, body, true)
41   rescue Exception => e
42     if @silent
43       warn e
44       return -1, {}
45     else
46       raise e
47     end
48   end
49 end