dogapi 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +1,100 @@
1
- Ruby client for Datadog API v1.0.3
1
+ = Ruby client for Datadog API v1.1.0
2
2
 
3
3
  The Ruby client is a library suitable for inclusion in existing Ruby projects or for development of standalone scripts. It provides an abstraction on top of Datadog's raw HTTP interface for reporting events and metrics.
4
4
 
5
5
  = Installation
6
6
 
7
- == Source
7
+ == From Source
8
8
 
9
9
  Available at: https://github.com/DataDog/dogapi-rb
10
10
 
11
- $ cd dogapi-rb
12
- $ rake gem
13
- $ gem install pkg/dogapi-*.gem
11
+ $ cd dogapi-rb
12
+ $ rake gem
13
+ $ gem install pkg/dogapi-*.gem
14
14
 
15
- == RubyGems
15
+ == Using RubyGems
16
16
 
17
17
  Gem page: https://rubygems.org/gems/dogapi
18
18
 
19
- $ gem install dogapi
19
+ $ gem install dogapi
20
20
 
21
21
  = Usage
22
22
 
23
- The client expects the +DATADOG_HOST+ environment variable to be set to the host you will be submitting data to:
23
+ == How to find your API Key
24
24
 
25
- $ export DATADOG_HOST=http://app.datadoghq.com/
25
+ Go to your setup page[https://app.datadoghq.com/account/settings].
26
26
 
27
- Minimal example:
27
+ == A word about hosts and devices
28
28
 
29
- require 'rubygems'
30
- require 'dogapi'
31
-
32
- dog = Dogapi::Client.new(@api_key)
33
- dog.emit_point 'some.metric.name', 50.0
29
+ Events and metric data points can be attached to hosts
30
+ to take advantage of automatic tagging with the host's tags.
34
31
 
35
- Further usage examples are available in the source distribution under <code>examples/</code> and <code>tests/</code>.
32
+ If you want to attach events and points to a specific device
33
+ on a host, simply specify the device when calling emit functions.
34
+
35
+ == Submit an event to Datadog
36
+
37
+ === If the event has no duration
38
+
39
+ require 'rubygems'
40
+ require 'dogapi'
41
+
42
+ api_key = "abcdef123456"
43
+
44
+ dog = Dogapi::Client.new(api_key)
45
+
46
+ dog.emit_event(Dogapi::Event.new('Testing done, FTW'), host => "my_host")
47
+
48
+ === If the event has a duration
49
+
50
+ require 'rubygems'
51
+ require 'dogapi'
52
+
53
+ api_key = "abcdef123456"
54
+
55
+ dog = Dogapi::Client.new(api_key)
56
+
57
+ dog.start_event(Dogapi::Event.new('My event with a duration'), host => "my_host") do
58
+ # do your work here...
59
+ # e.g. sleep 1
60
+ end
61
+ # stop_event will be sent automatically
62
+
63
+ == Submit a metric to Datadog
64
+
65
+ You want to track a new metric called +some.metric.name+ and have just sampled it from +my_device+ on +my_host+.
66
+ Its value is 50. Here is how you submit the value to Datadog.
67
+
68
+ require 'rubygems'
69
+ require 'dogapi'
70
+
71
+ api_key = "abcdef123456"
72
+
73
+ dog = Dogapi::Client.new(api_key)
74
+
75
+ dog.emit_point 'some.metric.name', 50.0, host => "my_host", device => "my_device"
76
+
77
+ Let us now assume that you have sampled the metric multiple times and you would like to submit the results.
78
+ You can use the +emit_points+ method (instead of +emit_point+). Since you are submitting more than one
79
+ data point you will need to pass a list of +Time+, +float+ pairs, instead of a simple +float+ value.
80
+
81
+ require 'rubygems'
82
+ require 'dogapi'
83
+
84
+ = Actual sampling takes place
85
+ t1 = Time.now
86
+ val1 = 50.0
87
+
88
+ = some time elapses
89
+ t2 = Time.now
90
+ val2 = 51.0
91
+
92
+ = some more time elapses
93
+ t3 = Time.now
94
+ val3 = -60.0
95
+
96
+ api_key = "abcdef123456"
97
+
98
+ dog = Dogapi::Client.new(api_key)
99
+
100
+ dog.emit_points 'some.metric.name', [[t1, val1], [t2, val2], [t3, val3]], host => "my_host", device => "my_device"
@@ -20,24 +20,21 @@ module Dogapi
20
20
 
21
21
  # Superclass that deals with the details of communicating with the DataDog API
22
22
  class Service
23
- def initialize(api_host=find_datadog_host)
23
+ def initialize(api_key, api_host=Dogapi.find_datadog_host)
24
+ @api_key = api_key
24
25
  @host = api_host
25
26
  end
26
27
 
27
28
  # Manages the HTTP connection
28
- def connect(api_key=nil, host=nil)
29
-
30
- @api_key = api_key
31
- host = host || @host
32
-
33
- uri = URI.parse(host)
29
+ def connect
30
+ uri = URI.parse(@host)
34
31
  session = Net::HTTP.new(uri.host, uri.port)
35
32
  if 'https' == uri.scheme
36
33
  session.use_ssl = true
37
- session.verify_mode = OpenSSL::SSL::VERIFY_PEER
38
- if File.directory? '/etc/ssl/certs'
39
- session.ca_path = '/etc/ssl/certs'
40
- end
34
+ # FIXME - turn off SSL verification for now until we can spend
35
+ # some time figuring out how to find certs across platforms.
36
+ # - matt 10/06/2011
37
+ session.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
38
  end
42
39
  session.start do |conn|
43
40
  yield(conn)
@@ -75,14 +72,9 @@ module Dogapi
75
72
  end
76
73
  end
77
74
 
78
- private
79
-
80
75
  def Dogapi.find_datadog_host
81
- ENV['DATADOG_HOST'] rescue "app.datadoghq.com"
82
- end
83
-
84
- def Dogapi.find_api_key
85
- ENV['DATADOG_KEY'] rescue nil
76
+ # allow env-based overriding, useful for tests
77
+ ENV["DATADOG_HOST"] || "https://app.datadoghq.com"
86
78
  end
87
79
 
88
80
  def Dogapi.find_localhost
@@ -18,9 +18,6 @@ module Dogapi
18
18
  end
19
19
 
20
20
  @datadog_host = Dogapi.find_datadog_host()
21
- if !@datadog_host
22
- raise 'DATADOG_HOST env variable not set'
23
- end
24
21
 
25
22
  @host = host
26
23
  @device = device
@@ -4,17 +4,7 @@ require 'dogapi'
4
4
  class TestClient < Test::Unit::TestCase
5
5
 
6
6
  def config_client_test_env
7
- @api_key = Dogapi.find_api_key
8
- if !@api_key
9
- @api_key = 'apikey_2'
10
- ENV['DATADOG_KEY'] = @api_key
11
- end
12
-
13
- @host = Dogapi.find_datadog_host
14
- if !@host
15
- @host = 'localhost:5000'
16
- ENV['DATADOG_HOST'] = @host
17
- end
7
+ @api_key = ENV['DATADOG_KEY']
18
8
  end
19
9
 
20
10
  def setup
@@ -5,25 +5,19 @@ class TestEnvironment < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  @host = ENV['DATADOG_HOST']
8
- @key = ENV['DATADOG_KEY']
9
8
  end
10
9
 
11
10
  def teardown
12
11
  ENV['DATADOG_HOST'] = @host
13
- ENV['DATADOG_KEY'] = @key
14
12
  end
15
13
 
16
14
  def test_unset
17
15
  ENV['DATADOG_HOST'] = nil
18
- ENV['DATADOG_KEY'] = nil
19
- assert_equal nil, Dogapi.find_datadog_host
20
- assert_equal nil, Dogapi.find_api_key
16
+ assert_equal "https://app.datadoghq.com", Dogapi.find_datadog_host
21
17
  end
22
18
 
23
19
  def test_set
24
20
  ENV['DATADOG_HOST'] = 'test.host'
25
- ENV['DATADOG_KEY'] = 'test_key'
26
21
  assert_equal 'test.host', Dogapi.find_datadog_host
27
- assert_equal 'test_key', Dogapi.find_api_key
28
22
  end
29
23
  end
@@ -4,17 +4,7 @@ require 'dogapi'
4
4
  class TestEventClient < Test::Unit::TestCase
5
5
 
6
6
  def config_client_test_env
7
- @api_key = Dogapi.find_api_key
8
- if !@api_key
9
- @api_key = 'apikey_2'
10
- ENV['DATADOG_KEY'] = @api_key
11
- end
12
-
13
- @host = Dogapi.find_datadog_host
14
- if !@host
15
- @host = 'localhost:5000'
16
- ENV['DATADOG_HOST'] = @host
17
- end
7
+ @api_key = ENV['DATADOG_KEY']
18
8
  end
19
9
 
20
10
  def setup
@@ -5,17 +5,7 @@ require 'dogapi'
5
5
  class TestMetricClient < Test::Unit::TestCase
6
6
 
7
7
  def config_client_test_env
8
- @api_key = Dogapi.find_api_key
9
- if !@api_key
10
- @api_key = 'apikey_2'
11
- ENV['DATADOG_KEY'] = @api_key
12
- end
13
-
14
- @host = Dogapi.find_datadog_host
15
- if !@host
16
- @host = 'localhost:5000'
17
- ENV['DATADOG_HOST'] = @host
18
- end
8
+ @api_key = ENV['DATADOG_KEY']
19
9
  end
20
10
 
21
11
  def setup
@@ -34,14 +24,6 @@ class TestMetricClient < Test::Unit::TestCase
34
24
  ]
35
25
  res = metric_service.submit(@api_key, scope, metric, points)
36
26
  assert_equal(res['status'], 'ok')
37
- assert_equal(res['results'].size, 1)
38
- r = res['results'][0]
39
- assert_equal(r['host'], scope.host)
40
- if scope.device
41
- assert_equal(r['device'], scope.device)
42
- end
43
- assert_equal(r['metric'], metric)
44
- assert_equal(r['length'], points.size)
45
27
  end
46
28
 
47
29
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogapi
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 1
8
+ - 1
7
9
  - 0
8
- - 4
9
- version: 1.0.4
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Datadog, Inc.
@@ -14,16 +15,17 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-10-06 00:00:00 -04:00
18
- default_executable:
18
+ date: 2011-10-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
28
+ hash: 1
27
29
  segments:
28
30
  - 1
29
31
  - 5
@@ -51,7 +53,6 @@ files:
51
53
  - tests/tc_metric.rb
52
54
  - tests/ts_dogapi.rb
53
55
  - README.rdoc
54
- has_rdoc: true
55
56
  homepage: http://datadoghq.com/
56
57
  licenses:
57
58
  - BSD
@@ -66,23 +67,27 @@ rdoc_options:
66
67
  require_paths:
67
68
  - lib
68
69
  required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
69
71
  requirements:
70
72
  - - ">="
71
73
  - !ruby/object:Gem::Version
74
+ hash: 3
72
75
  segments:
73
76
  - 0
74
77
  version: "0"
75
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
76
80
  requirements:
77
81
  - - ">="
78
82
  - !ruby/object:Gem::Version
83
+ hash: 3
79
84
  segments:
80
85
  - 0
81
86
  version: "0"
82
87
  requirements: []
83
88
 
84
89
  rubyforge_project:
85
- rubygems_version: 1.3.6
90
+ rubygems_version: 1.8.6
86
91
  signing_key:
87
92
  specification_version: 3
88
93
  summary: Ruby bindings for Datadog's API