Skip to content

Commit

Permalink
remove checks that do not actually make sense anymore
Browse files Browse the repository at this point in the history
We previously checked if `sys-proctable` was greater than `0.9.8` when it was originally introduced in 3204498#diff-681f43ba752e5217d82b23a247fd5c79 it was `0.9.6` which would have fit this condition. We are currently requiring `0.9.8` which makes this check of no real value. We are now requiring `~> 1.1`.

On top of that I am not sure the logic actually was ever correct but I don't care enough to check if that is right as it is now irrelevant.

Signed-off-by: Ben Abrams <[email protected]>
  • Loading branch information
majormoses committed Dec 5, 2017
1 parent 27d77c4 commit d26d47f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 47 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins

## [Unreleased]

### Changed
- bump and loosen dependency of `sys-proctable` (@majormoses)

### Removed
- check-threads-count.rb, metrics-processes-threads-count.rb: checks on `sys-proctable` versions as we now require new enough versions. (@majormoses)

## [2.5.0] - 2017-10-04
### Added
- metric-per-processes.py: Add metrics filter (@rthouvenin)
Expand Down
19 changes: 4 additions & 15 deletions bin/check-threads-count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ class ThreadsCount < Sensu::Plugin::Check::CLI
default: 32_000,
proc: proc(&:to_i)

PROCTABLE_MSG = 'sys-proctable version newer than 0.9.5 is required for counting threads with -t or --threads'.freeze

# Exit with an unknown if sys-proctable is not high enough to support counting threads.
def check_proctable_version
Gem.loaded_specs['sys-proctable'].version > Gem::Version.create('0.9.5')
end

# Takes a value to be tested as an integer. If a new Integer instance cannot be created from it, return 1.
# See the comments on get_process_threads() for why 1 is returned.
def test_int(i)
Expand Down Expand Up @@ -86,13 +79,9 @@ def count_threads

# Main function
def run
if !check_proctable_version
unknown PROCTABLE_MSG unless check_proctable_version
else
threads = count_threads
critical "#{threads} threads running, over threshold #{config[:crit]}" if threads > config[:crit]
warning "#{threads} threads running, over threshold #{config[:warn]}" if threads > config[:warn]
ok "#{threads} threads running"
end
threads = count_threads
critical "#{threads} threads running, over threshold #{config[:crit]}" if threads > config[:crit]
warning "#{threads} threads running, over threshold #{config[:warn]}" if threads > config[:warn]
ok "#{threads} threads running"
end
end
10 changes: 0 additions & 10 deletions bin/metrics-processes-threads-count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ class ProcessesThreadsCount < Sensu::Plugin::Metric::CLI::Graphite
boolean: true,
default: false

PROCTABLE_MSG = 'sys-proctable version newer than 0.9.5 is required for counting threads with -t or --threads'.freeze

# Exit with an unknown if sys-proctable is not high enough to support counting threads.
def check_proctable_version
Gem.loaded_specs['sys-proctable'].version > Gem::Version.create('0.9.5')
end

# Takes a value to be tested as an integer. If a new Integer instance cannot be created from it, return 1.
# See the comments on get_process_threads() for why 1 is returned.
def test_int(i)
Expand Down Expand Up @@ -112,9 +105,6 @@ def count_processes_by_status(ps_table)

# Main function
def run
if config[:threads] || config[:statuses]
unknown PROCTABLE_MSG unless check_proctable_version
end
ps_table = Sys::ProcTable.ps
processes = ps_table.length
threads = count_threads(ps_table) if config[:threads]
Expand Down
4 changes: 2 additions & 2 deletions sensu-plugins-process-checks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'english', '0.6.3'
s.add_runtime_dependency 'sensu-plugin', '~> 1.2'
s.add_runtime_dependency 'sys-proctable', '0.9.8'
s.add_runtime_dependency 'sys-proctable', '~> 1.1'

s.add_development_dependency 'bundler', '~> 1.7'
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
s.add_development_dependency 'github-markup', '~> 1.3'
s.add_development_dependency 'pry', '~> 0.10'
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'redcarpet', '~> 3.2'
s.add_development_dependency 'rspec', '~> 3.1'
s.add_development_dependency 'rubocop', '~> 0.40.0'
s.add_development_dependency 'redcarpet', '~> 3.2'
s.add_development_dependency 'yard', '~> 0.8'
end
8 changes: 0 additions & 8 deletions test/check-threads-count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@
end

describe ThreadsCount, 'run' do
it 'returns unknown if check_proctable_version returns false' do
threadscount = ThreadsCount.new
allow(threadscount).to receive(:count_threads).and_return(0)
allow(threadscount).to receive(:check_proctable_version).and_return(false)
expect(threadscount).to receive(:unknown)
threadscount.run
end

it 'returns critical if count_threads returns more than the critical threshold' do
threadscount = ThreadsCount.new
threadscount.config[:warn] = 10
Expand Down
12 changes: 0 additions & 12 deletions test/metrics-processes-threads-count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@
end

describe ThreadsCount, 'run' do
it 'returns unknown if check_proctable_version returns false and config[:threads] is true' do
nlwp_entry = Struct.new(:thread_count)
table = [nlwp_entry.new(3), nlwp_entry.new(1), nlwp_entry.new(6)]
allow(Sys::ProcTable).to receive(:ps).and_return(table)
ptcount = ProcessesThreadsCount.new
ptcount.config[:threads] = true
allow(ptcount).to receive(:count_threads).and_return(0)
allow(ptcount).to receive(:check_proctable_version).and_return(false)
expect(ptcount).to receive(:unknown)
expect(-> { ptcount.run }).to raise_error SystemExit
end

it 'does not return unknown if check_proctable_version returns false and config[:threads] is false' do
nlwp_entry = Struct.new(:thread_count)
table = [nlwp_entry.new(3), nlwp_entry.new(1), nlwp_entry.new(6)]
Expand Down

0 comments on commit d26d47f

Please sign in to comment.