Class: GraphiteInterface

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.events_enabled(action) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/capistrano/graphite.rb', line 10

def self.events_enabled(action)
  if fetch(:graphite_enable_events).to_i == 1
    # We only post an event if graphite_enable_events was set to 1
    GraphiteInterface.new.post_event(action)
    return 1
  elsif fetch(:graphite_enable_events).to_i == 0
    return 0
  else
    return -1
  end
end

Instance Method Details

#post_event(action) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/capistrano/graphite.rb', line 22

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 = "{\"what\": \"#{action} #{fetch(:application)} in #{fetch(:stage)}\", \"tags\": \"#{fetch(:application)},#{fetch(:stage)},#{release_timestamp},#{action}\", \"data\": \"#{fetch(:local_user)}\"}"

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