Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metric] support for metric query #90

Merged
merged 2 commits into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
Gemfile.lock
doc/
pkg/
.idea
22 changes: 22 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,25 @@ data point you will need to pass a list of +Time+, +float+ pairs, instead of a s
dog = Dogapi::Client.new(api_key)

dog.emit_points('some.metric.name', [[t1, val1], [t2, val2], [t3, val3]], :host => "my_host", :device => "my_device")


== Get points from a Datadog metric

require 'rubygems'
require 'dogapi'

api_key = "abcd123"
application_key = "brec1252"

dog = Dogapi::Client.new(api_key, application_key)

# get points from the last hour
from = Time.now - 3600
to = Time.now

query = 'sum:metric.count{*}.as_count()'

dog.get_points(from, to, query)



10 changes: 10 additions & 0 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def emit_points(metric, points, options = {})
@metric_svc.submit(metric, points, scope, options)
end

# Get a set of points by query between from and to
#
# +from+ The seconds since the unix epoch <tt>[Time, Integer]</tt>
# +to+ The seconds since the unix epoch <tt>[Time, Integer]</tt>
# +query+ The query string <tt>[String]</tt>
#
def get_points(query, from, to)
@metric_svc.get(query, from, to)
end

def batch_metrics()
@metric_svc.switch_to_batched
begin
Expand Down
21 changes: 21 additions & 0 deletions lib/dogapi/v1/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ class MetricService < Dogapi::APIService

API_VERSION = "v1"

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

def upload(metrics)
begin
params = {
Expand Down