Permalink
Browse files

v1.3.1 Added tags to emit_point and emit_points.

Allow metrics to be typed (fixes #6)
  • Loading branch information...
1 parent 37c24cb commit bcb68c3201b15e7f9ffba76804f2b8d8f6d54364 @alq666 alq666 committed May 24, 2012
Showing with 32 additions and 4 deletions.
  1. +1 −1 VERSION
  2. +8 −0 lib/dogapi/facade.rb
  3. +13 −3 lib/dogapi/v1/metric.rb
  4. +10 −0 tests/test_client.rb
View
@@ -1 +1 @@
-1.3.0
+1.3.1
View
@@ -42,6 +42,10 @@ def initialize(api_key, application_key=nil, host=nil, device=nil)
# :timestamp => Ruby stdlib Time
# :host => String
# :device => String
+ # :options => Map
+ #
+ # options[:type] = "counter" to specify a counter metric
+ # options[:tags] = ["tag1", "tag2"] to tag the point
def emit_point(metric, value, options={})
defaults = {:timestamp => Time.now, :host => nil, :device => nil}
options = defaults.merge(options)
@@ -58,6 +62,10 @@ def emit_point(metric, value, options={})
# Optional arguments:
# :host => String
# :device => String
+ # :options => Map
+ #
+ # options[:type] = "counter" to specify a counter metric
+ # options[:tags] = ["tag1", "tag2"] to tag the point
def emit_points(metric, points, options={})
defaults = {:host => nil, :device => nil}
options = defaults.merge(options)
View
@@ -13,19 +13,29 @@ def submit(metric, points, scope, options={})
params = {
:api_key => @api_key
}
- type = options[:type] || "gauge"
+ typ = options[:type] || "gauge"
+
+ if typ != "gauge" && typ == "counter"
+ raise ArgumentError, "metric type must be gauge or counter"
+ end
body = { :series => [
{
:metric => metric,
:points => points,
- :type => type,
+ :type => typ,
:host => scope.host,
:device => scope.device
}
]
}
- #puts 'POSTING ' + body.inspect
+
+
+ # Add tags if there are any
+ if not options[:tags].nil?
+ body[:series][0][:tags] = options[:tags]
+ end
+
request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', params, body, true)
end
end
View
@@ -90,6 +90,14 @@ def test_events
assert now_event['text'] == now_message
assert before_event['text'] == before_message
+
+ # Testing priorities
+ code, resp = dog_r.emit_event(Dogapi::Event.new(now_message, :msg_title =>now_title, :date_happened => now_ts, :priority => "low"))
+ low_event_id = resp["event"]["id"]
+ code, resp = dog.get_event(low_event_id)
+ low_event = resp['event']
+ puts low_event
+ assert low_event['priority'] == "low"
end
def test_metrics
@@ -99,6 +107,8 @@ def test_metrics
dog_r.emit_point('test.metric.metric', 10, :host => 'test.metric.host')
dog_r.emit_points('test.metric.metric', [[Time.now-5*60, 0]], :host => 'test.metric.host')
+
+ dog_r.emit_points('test.metric.metric', [[Time.now-60, 20], [Time.now-30, 10], [Time.now, 5]], :tags => ["test:tag.1", "test:tag2"])
end
end

0 comments on commit bcb68c3

Please sign in to comment.