Class: FFWD::Plugin::Datadog::Hook
- Inherits:
-
FlushingOutputHook
- Object
- FlushingOutputHook
- FFWD::Plugin::Datadog::Hook
- Defined in:
- lib/ffwd/plugin/datadog/hook.rb
Constant Summary collapse
- HEADER =
{ "Content-Type" => "application/json" }
- API_PATH =
"/api/v1/series"
Instance Method Summary collapse
- #active? ⇒ Boolean
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize(url, datadog_key) ⇒ Hook
constructor
A new instance of Hook.
- #reporter_meta ⇒ Object
- #send(metrics) ⇒ Object
Constructor Details
#initialize(url, datadog_key) ⇒ Hook
Returns a new instance of Hook.
30 31 32 33 34 |
# File 'lib/ffwd/plugin/datadog/hook.rb', line 30 def initialize url, datadog_key @c = nil @url = url @datadog_key = datadog_key end |
Instance Method Details
#active? ⇒ Boolean
36 37 38 |
# File 'lib/ffwd/plugin/datadog/hook.rb', line 36 def active? not @c.nil? end |
#close ⇒ Object
44 45 46 47 |
# File 'lib/ffwd/plugin/datadog/hook.rb', line 44 def close @c.close @c = nil end |
#connect ⇒ Object
40 41 42 |
# File 'lib/ffwd/plugin/datadog/hook.rb', line 40 def connect @c = EM::HttpRequest.new(@url) end |
#reporter_meta ⇒ Object
59 60 61 |
# File 'lib/ffwd/plugin/datadog/hook.rb', line 59 def {:component => :datadog} end |
#send(metrics) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/ffwd/plugin/datadog/hook.rb', line 49 def send metrics metrics = Utils.make_metrics(metrics) metrics = JSON.dump(metrics) @c.post(:path => API_PATH, :query => {'api_key' => @datadog_key }, :head => HEADER, :body => metrics) end |