Class: FFWD::Plugin::KairosDB::Hook

Inherits:
FlushingOutputHook
  • Object
show all
Defined in:
lib/ffwd/plugin/kairosdb/hook.rb

Constant Summary collapse

HEADER =
{
  "Content-Type" => "application/json"
}
API_PATH =
"/api/v1/series"

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Hook

Returns a new instance of Hook.



30
31
32
33
# File 'lib/ffwd/plugin/kairosdb/hook.rb', line 30

def initialize url
  @c = nil
  @url = url
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ffwd/plugin/kairosdb/hook.rb', line 35

def active?
  not @c.nil?
end

#closeObject



43
44
45
46
# File 'lib/ffwd/plugin/kairosdb/hook.rb', line 43

def close
  @c.close
  @c = nil
end

#connectObject



39
40
41
# File 'lib/ffwd/plugin/kairosdb/hook.rb', line 39

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

#reporter_metaObject



54
55
56
# File 'lib/ffwd/plugin/kairosdb/hook.rb', line 54

def reporter_meta
  {:component => :datadog}
end

#send(metrics) ⇒ Object



48
49
50
51
52
# File 'lib/ffwd/plugin/kairosdb/hook.rb', line 48

def send metrics
  metrics = Utils.make_metrics(metrics)
  metrics = JSON.dump(metrics)
  @c.post(:path => API_PATH, :head => HEADER, :body => metrics)
end