sensu-plugins-load-checks 2.0.0 → 3.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: 298dd4b0198829f6f6fd1a5761cbe41104072281
4
- data.tar.gz: f1ef98ca9e411273db36bffb5801ee6bc06e2ddb
3
+ metadata.gz: a74c9211d11a36e37fe0f3dd48985d29c597bef5
4
+ data.tar.gz: 06f2abfce99cc3d92adfd27821fdf00dc5adf1a1
5
5
  SHA512:
6
- metadata.gz: 74983811f7e704e45f89c0bba37f1b2c0733e3036a9ba149a335e1949844699c4da5c32c929963fdcfc582d990fca184a2efa3228f4e26ff58fb82ebfcfc380d
7
- data.tar.gz: 5fd34a60ee3119d59e5901cf1b220d7301c70163c7e402fa27541aa33e64813cbfbb8664833b14dd379d0a28f2ae3b80ecf130b920f6a6b46daf261b352b6fad
6
+ metadata.gz: ae29e7df1a2d14a3edab287ebcc4ba29a18ffcaf12c952eca2a8eb8af2120b93b4545d986bfc7b1e948634899a72d87c210a2a85e9f44fafcce1a767506cc45e
7
+ data.tar.gz: 5d117481dc2a814274fe5b578720230cde4534cbad9e8d4134cc0c50f271f8b24e78c5afdb03ae2c86659705ee9e32300751721a7b4bf980109e624e1cec1d42
@@ -4,10 +4,19 @@ 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
+ ## [3.0.0]
8
+ ### Breaking Change
9
+ - bin/check-load.rb remove option for per_core as its useless and broken (@majormoses)
10
+ - bin/metrics-load.rb remove option for per_core as its useless and broken (@majormoses)
11
+
12
+ ### Changed
13
+ - moved common logic into its own library location (@majormoses)
14
+ ### Fixed
15
+ - bin/metrics-load.rb now uses common logic which fixes issues with uptime LOCALE parsing (@majormoses)
16
+
7
17
  ### [2.0.0]
8
18
  ### Breaking Change
9
19
  - bin/check-load.rb change the default of per_core to true (@majormoses)
10
-
11
20
  ### Changed
12
21
  - Use the `uptime` command in bin/check-load.rb as well (@smuth4)
13
22
  - Correctly detect the number of cores on BSD (@smuth4)
@@ -43,7 +52,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
43
52
  ### Added
44
53
  - initial release
45
54
 
46
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/2.0.0...HEAD
55
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/3.0.0...HEAD
56
+ [3.0.0]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/2.0.0...3.0.0
47
57
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/1.0.0...2.0.0
48
58
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/0.0.4...1.0.0
49
59
  [0.0.4]: https://github.com/sensu-plugins/sensu-plugins-load-checks/compare/0.0.3...0.0.4
data/README.md CHANGED
@@ -21,11 +21,10 @@ To see the list of full options you can run:
21
21
  $ ./bin/check-load.rb --help
22
22
  Usage: ./bin/check-load.rb (options)
23
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
24
  -w, --warn L1,L5,L15 Load WARNING threshold, 1/5/15 min average
26
25
  ```
27
26
 
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.
27
+ This check should work on linux systems and many other unix systems. The check takes 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
28
 
30
29
 
31
30
  ## Installation
@@ -24,47 +24,7 @@
24
24
  #
25
25
 
26
26
  require 'sensu-plugin/check/cli'
27
-
28
- class LoadAverage
29
- def initialize(per_core = true)
30
- @cores = per_core ? cpu_count : 1
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
40
- end
41
-
42
- def cpu_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
48
- rescue
49
- 0
50
- end
51
-
52
- def failed?
53
- @avg.nil? || @cores.zero?
54
- end
55
-
56
- def exceed?(thresholds)
57
- @avg.zip(thresholds).any? { |a, t| a >= t }
58
- end
59
-
60
- def to_s
61
- @avg.join(', ')
62
- end
63
-
64
- def total
65
- @avg.map { |a| (a * @cores) }.join(', ')
66
- end
67
- end
27
+ require_relative '../lib/sensu-plugins-load-checks/load-average.rb'
68
28
 
69
29
  class CheckLoad < Sensu::Plugin::Check::CLI
70
30
  option :warn,
@@ -81,25 +41,14 @@ class CheckLoad < Sensu::Plugin::Check::CLI
81
41
  proc: proc { |a| a.split(',').map(&:to_f) },
82
42
  default: [3.5, 3.25, 3.0]
83
43
 
84
- option :per_core,
85
- short: '-p',
86
- long: '--per-core',
87
- description: 'Divide load average results by cpu/core count',
88
- boolean: 'true',
89
- default: true
90
-
91
44
  def run
92
- avg = LoadAverage.new(config[:per_core])
93
- unknown 'Could not read load average from /proc' if avg.failed?
45
+ data = LoadAverage.new
46
+ unknown 'Could not read load average from /proc or `uptime`' if data.failed?
94
47
 
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
48
+ message "Per core load average (#{data.cpu_count} CPU): #{data.load_avg}"
100
49
 
101
- critical if avg.exceed?(config[:crit])
102
- warning if avg.exceed?(config[:warn])
50
+ critical if data.exceed?(config[:crit])
51
+ warning if data.exceed?(config[:warn])
103
52
  ok
104
53
  end
105
54
  end
@@ -21,7 +21,7 @@
21
21
  # metric data
22
22
  #
23
23
  # PLATFORMS:
24
- # Linux, Windows, BSD, Solaris, etc
24
+ # Linux, BSD, Solaris, etc
25
25
  #
26
26
  # DEPENDENCIES:
27
27
  # gem: sensu-plugin
@@ -38,6 +38,7 @@
38
38
  #
39
39
 
40
40
  require 'sensu-plugin/metric/cli'
41
+ require_relative '../lib/sensu-plugins-load-checks/load-average.rb'
41
42
  require 'socket'
42
43
 
43
44
  class LoadStat < Sensu::Plugin::Metric::CLI::Graphite
@@ -46,43 +47,18 @@ class LoadStat < Sensu::Plugin::Metric::CLI::Graphite
46
47
  long: '--scheme SCHEME',
47
48
  default: Socket.gethostname.to_s
48
49
 
49
- option :per_core,
50
- description: 'Divide load average results by cpu/core count',
51
- short: '-p',
52
- long: '--per-core',
53
- boolean: true,
54
- default: false
55
-
56
- def number_of_cores
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
62
- end
63
-
64
50
  def run
65
- result = `uptime`.delete(',').split(' ')
66
- result = result[-3..-1]
51
+ data = LoadAverage.new
52
+ unknown 'Could not read load average from /proc or `uptime`' if data.failed?
67
53
 
68
54
  timestamp = Time.now.to_i
69
- if config[:per_core]
70
- metrics = {
71
- load_avg: {
72
- one: (result[0].to_f / number_of_cores).round(2),
73
- five: (result[1].to_f / number_of_cores).round(2),
74
- fifteen: (result[2].to_f / number_of_cores).round(2)
75
- }
55
+ metrics = {
56
+ load_avg: {
57
+ one: data.load_avg[0].round(2),
58
+ five: data.load_avg[1].round(2),
59
+ fifteen: data.load_avg[2].round(2)
76
60
  }
77
- else
78
- metrics = {
79
- load_avg: {
80
- one: result[0],
81
- five: result[1],
82
- fifteen: result[2]
83
- }
84
- }
85
- end
61
+ }
86
62
 
87
63
  metrics.each do |parent, children|
88
64
  children.each do |child, value|
@@ -0,0 +1,42 @@
1
+ class LoadAverage
2
+ def initialize
3
+ @cores = cpu_count
4
+ @avg = load_avg
5
+ end
6
+
7
+ def load_avg
8
+ if File.exist?('/proc/loadavg')
9
+ # linux
10
+ File.read('/proc/loadavg').split.take(3).map { |a| (a.to_f / @cores).round(2) } rescue nil # rubocop:disable RescueModifier
11
+ else
12
+ # fallback for FreeBSD
13
+ `uptime`.split(' ')[-3..-1].map(&:to_f).map { |a| (a.to_f / @cores).round(2) } rescue nil # rubocop:disable RescueModifier
14
+ end
15
+ end
16
+
17
+ def cpu_count
18
+ if File.exist?('/proc/cpuinfo')
19
+ File.read('/proc/cpuinfo').scan(/^processor/).count
20
+ else
21
+ `sysctl -n hw.ncpu`.to_i
22
+ end
23
+ rescue
24
+ 0
25
+ end
26
+
27
+ def failed?
28
+ @avg.nil? || @cores.zero?
29
+ end
30
+
31
+ def exceed?(thresholds)
32
+ @avg.zip(thresholds).any? { |a, t| a >= t }
33
+ end
34
+
35
+ def to_s
36
+ @avg.join(', ')
37
+ end
38
+
39
+ def total
40
+ @avg.map { |a| (a / @cores) }.join(', ')
41
+ end
42
+ end
@@ -1,6 +1,6 @@
1
1
  module SensuPluginsLoadChecks
2
2
  module Version
3
- MAJOR = 2
3
+ MAJOR = 3
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: 2.0.0
4
+ version: 3.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: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -167,6 +167,7 @@ files:
167
167
  - bin/check-load.rb
168
168
  - bin/metrics-load.rb
169
169
  - lib/sensu-plugins-load-checks.rb
170
+ - lib/sensu-plugins-load-checks/load-average.rb
170
171
  - lib/sensu-plugins-load-checks/version.rb
171
172
  homepage: https://github.com/sensu-plugins/sensu-plugins-load-checks
172
173
  licenses: