Class: GraphiteInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/graphite.rb

Overview

Build the request to post

Instance Method Summary collapse

Instance Method Details

#event(action) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/capistrano/graphite.rb', line 26

def event(action)
  {
    'what' => fetch(:graphite_event_msg).call(action),
    'tags' => fetch(:graphite_event_tags).call(action),
    'data' => fetch(:graphite_event_data)
  }
end

#post_event(action) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capistrano/graphite.rb', line 12

def post_event(action)
  uri = URI.parse("#{fetch(:graphite_url)}")
  req = Net::HTTP::Post.new(uri.path)
  req.basic_auth(uri.user, uri.password) if uri.user
  req.body = event(action).to_json

  opts = { use_ssl: uri.scheme == 'https' } \
         .merge(fetch(:graphite_http_options))

  Net::HTTP.start(uri.host, uri.port, opts) do |http|
    http.request(req)
  end
end