sensu-plugins-cpu-checks 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -1
- data/bin/check-cpu.rb +54 -8
- data/bin/metrics-cpu.rb +1 -1
- data/lib/sensu-plugins-cpu-checks/version.rb +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a6b98e98d618673b465206bfeb594ed0e24fb5b
|
4
|
+
data.tar.gz: f6eb4d2c4e4b11dcd38736b52d5b764ee0da133e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a88af95700227ee0ed627a1d472ea357a408139a4e51e854649a200f6bae397524ecf4cc7ce2b7b5d8ccfb4d5316a884695afb02cbf07f7279a3994798dac6c4
|
7
|
+
data.tar.gz: 19baa85d8e554a4b36ea5b335d2c9dd185ad6c897935d0ba1c3cd9159f6c00a54b8de06ee2aa39392710f6efc62439da009347141459716ad9b4e32026e30a2e
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ 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
|
+
## [1.1.0] - 2017-05-02
|
8
|
+
### Changed
|
9
|
+
- no real change just bumping due to deployment issue.
|
10
|
+
|
11
|
+
## [1.1.0] - 2017-05-02
|
12
|
+
### Added
|
13
|
+
- check-cpu.rb: added option to check less than (@santhosh-tekuri)
|
14
|
+
- check-cpu.rb: added option to use a cache file rather than sleeping to look at previous times (@axos88)
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- Set the correct type for --proc-path (@envintus)
|
18
|
+
- metrics-cpu.rb was missing a column (@michau)
|
7
19
|
|
8
20
|
## [1.0.0] - 2016-06-15
|
9
21
|
### Changed
|
@@ -40,7 +52,9 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
40
52
|
- initial release
|
41
53
|
|
42
54
|
|
43
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/1.
|
55
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/1.1.1...HEAD
|
56
|
+
[1.1.1]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/1.1.0...1.1.0
|
57
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/1.0.0...1.1.0
|
44
58
|
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.4...1.0.0
|
45
59
|
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.3...0.0.4
|
46
60
|
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-cpu-checks/compare/0.0.2...0.0.3
|
data/bin/check-cpu.rb
CHANGED
@@ -26,6 +26,7 @@
|
|
26
26
|
#
|
27
27
|
|
28
28
|
require 'sensu-plugin/check/cli'
|
29
|
+
require 'json'
|
29
30
|
|
30
31
|
#
|
31
32
|
# Check CPU
|
@@ -33,6 +34,13 @@ require 'sensu-plugin/check/cli'
|
|
33
34
|
class CheckCPU < Sensu::Plugin::Check::CLI
|
34
35
|
CPU_METRICS = [:user, :nice, :system, :idle, :iowait, :irq, :softirq, :steal, :guest, :guest_nice].freeze
|
35
36
|
|
37
|
+
option :less_than,
|
38
|
+
description: 'Change whether value is less than check',
|
39
|
+
short: '-l',
|
40
|
+
long: '--less_than',
|
41
|
+
default: false,
|
42
|
+
boolean: true
|
43
|
+
|
36
44
|
option :warn,
|
37
45
|
short: '-w WARN',
|
38
46
|
proc: proc(&:to_f),
|
@@ -48,9 +56,13 @@ class CheckCPU < Sensu::Plugin::Check::CLI
|
|
48
56
|
proc: proc(&:to_f),
|
49
57
|
default: 1
|
50
58
|
|
59
|
+
option :cache_file,
|
60
|
+
long: '--cache-file CACHEFILE',
|
61
|
+
default: nil
|
62
|
+
|
51
63
|
option :proc_path,
|
52
64
|
long: '--proc-path /proc',
|
53
|
-
proc: proc(&:
|
65
|
+
proc: proc(&:to_s),
|
54
66
|
default: '/proc'
|
55
67
|
|
56
68
|
option :idle_metrics,
|
@@ -75,18 +87,47 @@ class CheckCPU < Sensu::Plugin::Check::CLI
|
|
75
87
|
end
|
76
88
|
end
|
77
89
|
|
90
|
+
def acquire_stats_with_sleeping(sec)
|
91
|
+
before = acquire_cpu_stats
|
92
|
+
sleep sec
|
93
|
+
after = acquire_cpu_stats
|
94
|
+
|
95
|
+
[before, after]
|
96
|
+
end
|
97
|
+
|
98
|
+
def acquire_stats_with_cache_file
|
99
|
+
before = JSON.parse(File.read(config[:cache_file]))
|
100
|
+
now = acquire_cpu_stats
|
101
|
+
|
102
|
+
[before, now]
|
103
|
+
end
|
104
|
+
|
105
|
+
def write_stats_to_cache_file(data)
|
106
|
+
File.write(config[:cache_file], data)
|
107
|
+
end
|
108
|
+
|
109
|
+
def acquire_stats(sec)
|
110
|
+
if config[:cache_file] && File.exist?(config[:cache_file])
|
111
|
+
(before, now) = acquire_stats_with_cache_file
|
112
|
+
else
|
113
|
+
(before, now) = acquire_stats_with_sleeping(sec)
|
114
|
+
end
|
115
|
+
|
116
|
+
write_stats_to_cache_file(now) if config[:cache_file]
|
117
|
+
|
118
|
+
[before, now]
|
119
|
+
end
|
120
|
+
|
78
121
|
def run
|
79
|
-
cpu_stats_before =
|
80
|
-
sleep config[:sleep]
|
81
|
-
cpu_stats_after = acquire_cpu_stats
|
122
|
+
(cpu_stats_before, cpu_stats_now) = acquire_stats(config[:sleep])
|
82
123
|
|
83
124
|
# Some kernels don't have 'guest' and 'guest_nice' values
|
84
|
-
metrics = CPU_METRICS.slice(0,
|
125
|
+
metrics = CPU_METRICS.slice(0, cpu_stats_now.length)
|
85
126
|
|
86
127
|
cpu_total_diff = 0.to_f
|
87
128
|
cpu_stats_diff = []
|
88
129
|
metrics.each_index do |i|
|
89
|
-
cpu_stats_diff[i] =
|
130
|
+
cpu_stats_diff[i] = cpu_stats_now[i] - cpu_stats_before[i]
|
90
131
|
cpu_total_diff += cpu_stats_diff[i]
|
91
132
|
end
|
92
133
|
|
@@ -113,8 +154,13 @@ class CheckCPU < Sensu::Plugin::Check::CLI
|
|
113
154
|
|
114
155
|
message msg
|
115
156
|
|
116
|
-
|
117
|
-
|
157
|
+
if config[:less_than]
|
158
|
+
critical if checked_usage <= config[:crit]
|
159
|
+
warning if checked_usage <= config[:warn]
|
160
|
+
else
|
161
|
+
critical if checked_usage >= config[:crit]
|
162
|
+
warning if checked_usage >= config[:warn]
|
163
|
+
end
|
118
164
|
ok
|
119
165
|
end
|
120
166
|
end
|
data/bin/metrics-cpu.rb
CHANGED
@@ -42,7 +42,7 @@ class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite
|
|
42
42
|
default: '/proc'
|
43
43
|
|
44
44
|
def run
|
45
|
-
cpu_metrics = %w(user nice system idle iowait irq softirq steal guest)
|
45
|
+
cpu_metrics = %w(user nice system idle iowait irq softirq steal guest guest_nice)
|
46
46
|
other_metrics = %w(ctxt processes procs_running procs_blocked btime intr)
|
47
47
|
cpu_count = 0
|
48
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-cpu-checks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
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:
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -217,9 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
217
|
version: '0'
|
218
218
|
requirements: []
|
219
219
|
rubyforge_project:
|
220
|
-
rubygems_version: 2.5
|
220
|
+
rubygems_version: 2.4.5
|
221
221
|
signing_key:
|
222
222
|
specification_version: 4
|
223
223
|
summary: Sensu plugins for cpu checks and metrics
|
224
224
|
test_files: []
|
225
|
-
has_rdoc:
|