Class: FFWD::Plugin::Datadog::Hook

Inherits:
FlushingOutputHook
  • Object
show all
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

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/ffwd/plugin/datadog/hook.rb', line 36

def active?
  not @c.nil?
end

#closeObject



44
45
46
47
# File 'lib/ffwd/plugin/datadog/hook.rb', line 44

def close
  @c.close
  @c = nil
end

#connectObject



40
41
42
# File 'lib/ffwd/plugin/datadog/hook.rb', line 40

def connect
  @c = EM::HttpRequest.new(@url)
end

#reporter_metaObject



59
60
61
# File 'lib/ffwd/plugin/datadog/hook.rb', line 59

def reporter_meta
  {: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