check-load.rb
1.27 KB
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
#! /usr/bin/env ruby
#
# check-load
#
# DESCRIPTION:
#
# OUTPUT:
# plain text
#
# PLATFORMS:
# Linux, BSD, Solaris, etc
#
# DEPENDENCIES:
# gem: sensu-plugin
#
# USAGE:
# ./bin/check-load.rb --help
# NOTES:
#
# LICENSE:
# Copyright 2012 Sonian, Inc <chefs@sonian.net>
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'sensu-plugin/check/cli'
require_relative '../lib/sensu-plugins-load-checks/load-average.rb'
class CheckLoad < Sensu::Plugin::Check::CLI
option :warn,
short: '-w L1,L5,L15',
long: '--warn L1,L5,L15',
description: 'Load WARNING threshold, 1/5/15 min average',
proc: proc { |a| a.split(',').map(&:to_f) },
default: [2.75, 2.5, 2.0]
option :crit,
short: '-c L1,L5,L15',
long: '--crit L1,L5,L15',
description: 'Load CRITICAL threshold, 1/5/15 min average',
proc: proc { |a| a.split(',').map(&:to_f) },
default: [3.5, 3.25, 3.0]
def run
data = LoadAverage.new
unknown 'Could not read load average from /proc or `uptime`' if data.failed?
message "Per core load average (#{data.cpu_count} CPU): #{data.load_avg}"
critical if data.exceed?(config[:crit])
warning if data.exceed?(config[:warn])
ok
end
end