-
Notifications
You must be signed in to change notification settings - Fork 57
/
check_oom-killer.rb
executable file
·75 lines (65 loc) · 2.47 KB
/
check_oom-killer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/env ruby
# -----------------------
# Author: Andreas Paul (xorpaul) <[email protected]>
# striped down to only contain oom killer check by
# Yornik Heyl<[email protected]> from https://github.com/xorpaul/check_linux/blob/master/check_linux.rb
# Date: 2013-12-02 10:57
# Version: 0.1.2
# -----------------------
require 'date'
require 'optparse'
require 'yaml'
def check_oom()
oom_cmd = "dmesg | awk '/invoked oom-killer:/ || /Killed process/'"
oom_data = `#{oom_cmd}`
lines_count = oom_data.split("\n").size
oom_result = {'perfdata' => "oom_killer_lines=#{lines_count}"}
if lines_count == 2
oom_result['returncode'] = 1
invoked_line, killed_line = oom_data.split("\n")
killed_pid = killed_line.split(" ")[3]
killed_cmd = "dmesg | grep #{killed_pid}]"
killed_data = `#{killed_cmd}`
killed_pid_rss = killed_data.split(" ")[-5].to_i
oom_result['text'] = "WARNING: #{invoked_line.split(" ")[1]} invoked oom-killer: #{killed_line.split(" ")[1..4].join(" ")} to free #{killed_pid_rss / 1024}MB - reset with dmesg -c when finished"
elsif lines_count > 3
# we can't match this with reasonable effort, so just scream for help
oom_result['returncode'] = 1
oom_result['text'] = "WARNING: oom-killer was invoked and went on a killing spree (dmesg | awk '/invoked oom-killer:/ || /Killed process/) - reset with dmesg -c when finished"
else
oom_result['returncode'] = 0
oom_result['text'] = "OK: No OOM killer activity found in dmesg output"
oom_result['perfdata'] = ''
end
return oom_result
end
results = []
results << check_oom()
puts "\n\nresult array: #{results}\n\n" if $debug
# Aggregate check results
output = {}
output['returncode'] = 0
output['text'] = ''
output['multiline'] = ''
output['perfdata'] = ''
results.each do |result|
output['perfdata'] += "#{result['perfdata']} " if result['perfdata'] != ''
if result['returncode'] >= 1
output['text'] += "#{result['text']} "
case result['returncode']
when 3
output['returncode'] = 3 if result['returncode'] > output['returncode']
when 2
output['returncode'] = 2 if result['returncode'] > output['returncode']
when 1
output['returncode'] = 1 if result['returncode'] > output['returncode']
end
else
output['multiline'] += "#{result['text']}</br>\n"
end
end
if output['text'] == ''
output['text'] = 'OK - everything looks okay'
end
puts "#{output['text']}|#{output['perfdata']}\n#{output['multiline'].chomp()}"
exit output['returncode']