Module: Capistrano::Notifier::Helpers::StatsD

Defined in:
lib/capistrano/notifier/helpers/statsd.rb

Instance Method Summary collapse

Instance Method Details

#applicationObject



5
6
7
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 5

def application
  fetch :application
end

#notifier_statsd_optionsObject



13
14
15
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 13

def notifier_statsd_options
  @notifier_statsd_options ||= fetch :notifier_statsd_options
end

#stageObject



9
10
11
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 9

def stage
  fetch :stage
end

#statsd_default_patternObject



41
42
43
44
45
46
47
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 41

def statsd_default_pattern
  if stage
    "#{application}.#{stage}.deploy"
  else
    "#{application}.deploy"
  end
end

#statsd_defaultsObject



17
18
19
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 17

def statsd_defaults
  { host: "127.0.0.1", port: "8125", with: :counter }
end

#statsd_hostObject



21
22
23
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 21

def statsd_host
  statsd_options[:host]
end

#statsd_notifier_commandObject



62
63
64
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 62

def statsd_notifier_command
  "echo -n #{statsd_packet} | nc -w 1 -u #{statsd_host} #{statsd_port}"
end

#statsd_optionsObject



25
26
27
28
29
30
31
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 25

def statsd_options
  @statsd_options ||= if notifier_statsd_options
                        statsd_defaults.merge notifier_statsd_options
                      else
                        statsd_defaults
                      end
end

#statsd_packetObject



33
34
35
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 33

def statsd_packet
  "#{statsd_pattern}:#{statsd_with}".gsub('|', '\\|')
end

#statsd_patternObject



37
38
39
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 37

def statsd_pattern
  statsd_options.fetch(:pattern){ statsd_default_pattern }
end

#statsd_portObject



49
50
51
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 49

def statsd_port
  statsd_options[:port]
end

#statsd_withObject



53
54
55
56
57
58
59
60
# File 'lib/capistrano/notifier/helpers/statsd.rb', line 53

def statsd_with
  case statsd_options[:with]
  when :counter
    "1|c"
  when :gauge
    "1|g"
  end
end