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 +4 -4
- data/CHANGELOG.md +12 -2
- data/README.md +1 -2
- data/bin/check-load.rb +6 -57
- data/bin/metrics-load.rb +10 -34
- data/lib/sensu-plugins-load-checks/load-average.rb +42 -0
- data/lib/sensu-plugins-load-checks/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74c9211d11a36e37fe0f3dd48985d29c597bef5
|
4
|
+
data.tar.gz: 06f2abfce99cc3d92adfd27821fdf00dc5adf1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae29e7df1a2d14a3edab287ebcc4ba29a18ffcaf12c952eca2a8eb8af2120b93b4545d986bfc7b1e948634899a72d87c210a2a85e9f44fafcce1a767506cc45e
|
7
|
+
data.tar.gz: 5d117481dc2a814274fe5b578720230cde4534cbad9e8d4134cc0c50f271f8b24e78c5afdb03ae2c86659705ee9e32300751721a7b4bf980109e624e1cec1d42
|
data/CHANGELOG.md
CHANGED
@@ -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/
|
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
|
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
|
data/bin/check-load.rb
CHANGED
@@ -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
|
-
|
93
|
-
unknown 'Could not read load average from /proc' if
|
45
|
+
data = LoadAverage.new
|
46
|
+
unknown 'Could not read load average from /proc or `uptime`' if data.failed?
|
94
47
|
|
95
|
-
|
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
|
102
|
-
warning if
|
50
|
+
critical if data.exceed?(config[:crit])
|
51
|
+
warning if data.exceed?(config[:warn])
|
103
52
|
ok
|
104
53
|
end
|
105
54
|
end
|
data/bin/metrics-load.rb
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
# metric data
|
22
22
|
#
|
23
23
|
# PLATFORMS:
|
24
|
-
# Linux,
|
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
|
-
|
66
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
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
|
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:
|
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-
|
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:
|