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, line 62 def flush_buffer() payload = @buffer @buffer = nil self.upload(payload) end
get(query, from, to)
click to toggle source
# File lib/dogapi/v1/metric.rb, line 11 def get(query, from, to) begin params = { :api_key => @api_key, :application_key => @application_key, from: from.to_i, to: to.to_i, query: query } request(Net::HTTP::Get, '/api/' + API_VERSION + '/query', params, nil, false) rescue Exception => e if @silent warn e return -1, {} else raise e end end end
make_metric_payload(metric, points, scope, options)
click to toggle source
# File lib/dogapi/v1/metric.rb, line 84 def make_metric_payload(metric, points, scope, options) begin typ = options[:type] || "gauge" if typ != "gauge" && typ != "counter" raise ArgumentError, "metric type must be gauge or counter" end metric_payload = { :metric => metric, :points => points, :type => typ, :host => scope.host, :device => scope.device } # Add tags if there are any if not options[:tags].nil? metric_payload[:tags] = options[:tags] end return metric_payload rescue Exception => e if @silent warn e return -1, {} else raise e end end end
submit(*args)
click to toggle source
# File lib/dogapi/v1/metric.rb, line 68 def submit(*args) if @buffer submit_to_buffer(*args) else submit_to_api(*args) end end
submit_to_api(metric, points, scope, options = {})
click to toggle source
# File lib/dogapi/v1/metric.rb, line 51 def submit_to_api(metric, points, scope, options = {}) payload = self.make_metric_payload(metric, points, scope, options) self.upload([payload]) end
submit_to_buffer(metric, points, scope, options = {})
click to toggle source
# File lib/dogapi/v1/metric.rb, line 56 def submit_to_buffer(metric, points, scope, options = {}) payload = self.make_metric_payload(metric, points, scope, options) @buffer << payload return 200, {} end
switch_to_batched()
click to toggle source
# File lib/dogapi/v1/metric.rb, line 76 def switch_to_batched() @buffer = Array.new end
switch_to_single()
click to toggle source
# File lib/dogapi/v1/metric.rb, line 80 def switch_to_single() @buffer = nil end
upload(metrics)
click to toggle source
# File lib/dogapi/v1/metric.rb, line 32 def upload(metrics) begin params = { :api_key => @api_key } body = { :series => metrics } request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', params, body, true) rescue Exception => e if @silent warn e return -1, {} else raise e end end end