Class: God::Contacts::Statsd

Inherits:
God::Contact show all
Defined in:
lib/god/contacts/statsd.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from God::Contact

#group, #info, #name

Instance Method Summary collapse

Methods inherited from God::Contact

#arg, defaults, #friendly_name, generate, normalize, valid?

Methods included from God::Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Class Attribute Details

.hostObject

Returns the value of attribute host



13
14
15
# File 'lib/god/contacts/statsd.rb', line 13

def host
  @host
end

.portObject

Returns the value of attribute port



13
14
15
# File 'lib/god/contacts/statsd.rb', line 13

def port
  @port
end

Instance Attribute Details

#hostObject

Returns the value of attribute host



16
17
18
# File 'lib/god/contacts/statsd.rb', line 16

def host
  @host
end

#portObject

Returns the value of attribute port



16
17
18
# File 'lib/god/contacts/statsd.rb', line 16

def port
  @port
end

Instance Method Details

#notify(message, time, priority, category, hostname) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/god/contacts/statsd.rb', line 24

def notify(message, time, priority, category, hostname)
  statsd = ::Statsd.new host, (port ? port.to_i : 8125) # 8125 is the default statsd port

  hostname.gsub! /\./, '_'
  app = message.gsub /([^\s]*).*/, '\1'

  [
      'cpu out of bounds',
      'memory out of bounds',
      'process is flapping'
  ].each do |event_type|
    statsd.increment "god.#{event_type.gsub(/\s/, '_')}.#{hostname}.#{app}" if message.include? event_type
  end

  self.info = 'sent statsd alert'
rescue => e
  applog(nil, :info, "failed to send statsd alert: #{e.message}")
  applog(nil, :debug, e.backtrace.join("\n"))
end

#valid?Boolean



18
19
20
21
22
# File 'lib/god/contacts/statsd.rb', line 18

def valid?
  valid = true
  valid &= complain("Attribute 'statsd_host' must be specified", self) unless arg(:host)
  valid
end