Class: CheckTCPMemory::Check

Inherits:
Nagios::Plugin
  • Object
show all
Defined in:
lib/check_tcp_memory/check.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Check

Returns a new instance of Check.



6
7
8
9
# File 'lib/check_tcp_memory/check.rb', line 6

def initialize(options)
  @warn_percent = options[:warn_percent]
  @crit_percent = options[:crit_percent]
end

Instance Method Details

#checkObject



23
24
25
26
27
28
29
30
31
# File 'lib/check_tcp_memory/check.rb', line 23

def check
  #@mem_max = File.read('/proc/sys/net/ipv4/tcp_mem').split()[2]
  @mem_max = File.read('/tmp/tcp_mem').split()[2].to_f
  #@current_usage = File.read('/proc/net/sockstat').gsub(':','').split("\n")   @current_usage = File.read('/tmp/sockstat').gsub(':','').split("\n")     .map{|a| b=a.split; Hash[b.shift, Hash[*b]]}     .reduce({}, :merge)['TCP']['mem'].to_f
  @percent_used = @current_usage / @mem_max
end

#critical?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/check_tcp_memory/check.rb', line 11

def critical?
  @percent_used >= @crit_percent
end

#messageObject



33
34
35
36
# File 'lib/check_tcp_memory/check.rb', line 33

def message
  "Percent Used: #{"%5.2f" % (@percent_used * 100)}%, "\
  "Current Usage: #{@current_usage}, Max TCP Memory: #{@mem_max}"
end

#ok?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/check_tcp_memory/check.rb', line 19

def ok?
  true
end

#warning?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/check_tcp_memory/check.rb', line 15

def warning?
  @percent_used >= @warn_percent
end