sensu-plugins-load-checks 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35df38a27bdf124cb968fcdd3598586d6b8a1553
4
- data.tar.gz: 2347a19c760f0d45cc110ac075deeb6fb94fffec
3
+ metadata.gz: 298dd4b0198829f6f6fd1a5761cbe41104072281
4
+ data.tar.gz: f1ef98ca9e411273db36bffb5801ee6bc06e2ddb
5
5
  SHA512:
6
- metadata.gz: 10b4639ff765690494188ca381cc37591329a766fe87d761ee7a944b85c9490f2fee0f744b99fbbb76c00e7e65a1e0fdd9bb3686449edfa233d156823f476786
7
- data.tar.gz: 59e6ea16f9bc1efbcbfed9206aa498fb1e3a4941035be4737992c9bdce638895913f33c319711065eaf9d740573bc492fc1a072dbd8c0aa4b556475b16bc5f29
6
+ metadata.gz: 74983811f7e704e45f89c0bba37f1b2c0733e3036a9ba149a335e1949844699c4da5c32c929963fdcfc582d990fca184a2efa3228f4e26ff58fb82ebfcfc380d
7
+ data.tar.gz: 5fd34a60ee3119d59e5901cf1b220d7301c70163c7e402fa27541aa33e64813cbfbb8664833b14dd379d0a28f2ae3b80ecf130b920f6a6b46daf261b352b6fad
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
6
  ## [Unreleased]
7
+ ### [2.0.0]
8
+ ### Breaking Change
9
+ - bin/check-load.rb change the default of per_core to true (@majormoses)
10
+
11
+ ### Changed
12
+ - Use the `uptime` command in bin/check-load.rb as well (@smuth4)
13
+ - Correctly detect the number of cores on BSD (@smuth4)
14
+ - bin/check-load.rb better output message (@woltage)
15
+ - bin/check-load.rb change the default thresholds to better align with per_core values (@majormoses)
16
+ - bin/check-load.rb changes to use >= rather than > for thresholds (@majormoses)
17
+ - bin/check-load.rb switch to using 'unknown' rather than 'warning' when unable to determine the load average (@majormoses)
7
18
 
8
19
  ## [1.0.0] - 2016-06-16
9
20
  ### Changed
@@ -32,7 +43,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
32
43
  ### Added
33
44
  - initial release
34
45
 
35
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/1.0.0...HEAD
46
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/2.0.0...HEAD
47
+ [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/1.0.0...2.0.0
36
48
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/0.0.4...1.0.0
37
49
  [0.0.4]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/0.0.3...0.0.4
38
50
  [0.0.3]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/0.0.2...0.0.3
data/README.md CHANGED
@@ -14,6 +14,20 @@
14
14
 
15
15
  ## Usage
16
16
 
17
+ ### check-load.rb
18
+
19
+ To see the list of full options you can run:
20
+ ```
21
+ $ ./bin/check-load.rb --help
22
+ Usage: ./bin/check-load.rb (options)
23
+ -c, --crit L1,L5,L15 Load CRITICAL threshold, 1/5/15 min average
24
+ -p, --per-core Divide load average results by cpu/core count
25
+ -w, --warn L1,L5,L15 Load WARNING threshold, 1/5/15 min average
26
+ ```
27
+
28
+ This check will only work on linux systems as it relies on `cat /proc/loadavg` and `cat /proc/cpuinfo`. The check now defaults to using the `per_core` option which will take the loadavg and divide by the number of cores. You can use `-w/-c` with a comma separated value for 1/5/15 minute thresholds.
29
+
30
+
17
31
  ## Installation
18
32
 
19
33
  [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
data/bin/check-load.rb CHANGED
@@ -8,13 +8,13 @@
8
8
  # plain text
9
9
  #
10
10
  # PLATFORMS:
11
- # Linux
11
+ # Linux, BSD, Solaris, etc
12
12
  #
13
13
  # DEPENDENCIES:
14
14
  # gem: sensu-plugin
15
15
  #
16
16
  # USAGE:
17
- #
17
+ # ./bin/check-load.rb --help
18
18
  # NOTES:
19
19
  #
20
20
  # LICENSE:
@@ -26,13 +26,25 @@
26
26
  require 'sensu-plugin/check/cli'
27
27
 
28
28
  class LoadAverage
29
- def initialize(per_core = false)
29
+ def initialize(per_core = true)
30
30
  @cores = per_core ? cpu_count : 1
31
- @avg = File.read('/proc/loadavg').split.take(3).map { |a| (a.to_f / @cores).round(2) } rescue nil # rubocop:disable RescueModifier
31
+ @avg = load_avg.map { |a| (a.to_f / @cores).round(2) } rescue nil # rubocop:disable RescueModifier
32
+ end
33
+
34
+ def load_avg
35
+ if File.exist?('/proc/loadavg')
36
+ File.read('/proc/loadavg').split.take(3)
37
+ else
38
+ `uptime`.delete(',').split(' ')[-3..-1]
39
+ end
32
40
  end
33
41
 
34
42
  def cpu_count
35
- File.read('/proc/cpuinfo').scan(/^processor/).count
43
+ if File.exist?('/proc/cpuinfo')
44
+ File.read('/proc/cpuinfo').scan(/^processor/).count
45
+ else
46
+ `sysctl -n hw.ncpu`.to_i
47
+ end
36
48
  rescue
37
49
  0
38
50
  end
@@ -42,12 +54,16 @@ class LoadAverage
42
54
  end
43
55
 
44
56
  def exceed?(thresholds)
45
- @avg.zip(thresholds).any? { |a, t| a > t }
57
+ @avg.zip(thresholds).any? { |a, t| a >= t }
46
58
  end
47
59
 
48
60
  def to_s
49
61
  @avg.join(', ')
50
62
  end
63
+
64
+ def total
65
+ @avg.map { |a| (a * @cores) }.join(', ')
66
+ end
51
67
  end
52
68
 
53
69
  class CheckLoad < Sensu::Plugin::Check::CLI
@@ -56,26 +72,32 @@ class CheckLoad < Sensu::Plugin::Check::CLI
56
72
  long: '--warn L1,L5,L15',
57
73
  description: 'Load WARNING threshold, 1/5/15 min average',
58
74
  proc: proc { |a| a.split(',').map(&:to_f) },
59
- default: [10, 20, 30]
75
+ default: [2.75, 2.5, 2.0]
60
76
 
61
77
  option :crit,
62
78
  short: '-c L1,L5,L15',
63
79
  long: '--crit L1,L5,L15',
64
80
  description: 'Load CRITICAL threshold, 1/5/15 min average',
65
81
  proc: proc { |a| a.split(',').map(&:to_f) },
66
- default: [25, 50, 75]
82
+ default: [3.5, 3.25, 3.0]
67
83
 
68
84
  option :per_core,
69
85
  short: '-p',
70
86
  long: '--per-core',
71
87
  description: 'Divide load average results by cpu/core count',
72
88
  boolean: 'true',
73
- default: false
89
+ default: true
74
90
 
75
91
  def run
76
92
  avg = LoadAverage.new(config[:per_core])
77
- warning 'Could not read load average from /proc' if avg.failed?
78
- message "Load average: #{avg}"
93
+ unknown 'Could not read load average from /proc' if avg.failed?
94
+
95
+ if config[:per_core] && avg.cpu_count > 1
96
+ message "Per core load average (#{avg.cpu_count} CPU): #{avg} - Total: #{avg.total}"
97
+ else
98
+ message "Total load average (#{avg.cpu_count} CPU): #{avg}"
99
+ end
100
+
79
101
  critical if avg.exceed?(config[:crit])
80
102
  warning if avg.exceed?(config[:warn])
81
103
  ok
data/bin/metrics-load.rb CHANGED
@@ -54,7 +54,11 @@ class LoadStat < Sensu::Plugin::Metric::CLI::Graphite
54
54
  default: false
55
55
 
56
56
  def number_of_cores
57
- @cores ||= File.readlines('/proc/cpuinfo').count { |l| l =~ /^processor\s+:/ }
57
+ @cores ||= if File.exist?('/proc/cpuinfo')
58
+ File.read('/proc/cpuinfo').scan(/^processor/).count
59
+ else
60
+ `sysctl -n hw.ncpu`.to_i
61
+ end
58
62
  end
59
63
 
60
64
  def run
@@ -1,6 +1,6 @@
1
1
  module SensuPluginsLoadChecks
2
2
  module Version
3
- MAJOR = 1
3
+ MAJOR = 2
4
4
  MINOR = 0
5
5
  PATCH = 0
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-load-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -194,9 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  requirements: []
196
196
  rubyforge_project:
197
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.4.5
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Sensu plugins for load checks
201
201
  test_files: []
202
- has_rdoc: