Class: CheckTCPMemory::Check
- Inherits:
-
Nagios::Plugin
- Object
- Nagios::Plugin
- CheckTCPMemory::Check
- Defined in:
- lib/check_tcp_memory/check.rb
Instance Method Summary collapse
- #check ⇒ Object
- #critical? ⇒ Boolean
-
#initialize(options) ⇒ Check
constructor
A new instance of Check.
- #message ⇒ Object
- #ok? ⇒ Boolean
- #warning? ⇒ Boolean
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() @warn_percent = [:warn_percent] @crit_percent = [:crit_percent] end |
Instance Method Details
#check ⇒ Object
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
11 12 13 |
# File 'lib/check_tcp_memory/check.rb', line 11 def critical? @percent_used >= @crit_percent end |
#message ⇒ Object
33 34 35 36 |
# File 'lib/check_tcp_memory/check.rb', line 33 def "Percent Used: #{"%5.2f" % (@percent_used * 100)}%, "\ "Current Usage: #{@current_usage}, Max TCP Memory: #{@mem_max}" end |
#ok? ⇒ Boolean
19 20 21 |
# File 'lib/check_tcp_memory/check.rb', line 19 def ok? true end |
#warning? ⇒ Boolean
15 16 17 |
# File 'lib/check_tcp_memory/check.rb', line 15 def warning? @percent_used >= @warn_percent end |