Skip to content

Commit

Permalink
Added -R to check-process.rb to address sensu-plugins#45
Browse files Browse the repository at this point in the history
Also includes some minor rubocop fixes
  • Loading branch information
Jonathan Gnagy committed Jun 16, 2017
1 parent 942e1a9 commit 13f4dd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ desc 'Test for binstubs'
task :check_binstubs do
bin_list = Gem::Specification.load('sensu-plugins-process-checks.gemspec').executables
bin_list.each do |b|
`which #{ b }`
unless $CHILD_STATUS.success?
unless system("which #{b} > /dev/null")
puts "#{b} was not a binstub"
exit
end
Expand Down
17 changes: 15 additions & 2 deletions bin/check-process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ class CheckProcess < Sensu::Plugin::Check::CLI
description: 'Trigger on a Virtual Memory size is bigger than this',
proc: proc(&:to_i)

# Alert if RSS is under this value
option :rss,
short: '-r RSS',
long: '--resident-set-size RSS',
description: 'Trigger on a Resident Set size is smaller than this',
proc: proc(&:to_i)

# Alert if RSS is over this value
option :over_rss,
short: '-R RSS',
long: '--over-resident-set-size RSS',
description: 'Trigger on a Resident Set size is bigger than this',
proc: proc(&:to_i)

Expand Down Expand Up @@ -209,7 +217,7 @@ def line_to_hash(line, *cols)
#
def on_cygwin?
# #YELLOW
`ps -W 2>&1`; $CHILD_STATUS.exitstatus == 0 # rubocop:disable Semicolon
`ps -W 2>&1`; $CHILD_STATUS.exitstatus.zero? # rubocop:disable Semicolon
end

# Acquire all the proceeses on a system for further analysis
Expand Down Expand Up @@ -249,6 +257,7 @@ def cputime_to_csec(time)

# The main function
#
# rubocop:disable Metrics/AbcSize
def run
procs = acquire_procs

Expand All @@ -261,7 +270,10 @@ def run
procs.reject! { |p| p[:command] =~ /#{config[:exclude_pat]}/ } if config[:exclude_pat]
procs.reject! { |p| p[:command] !~ /#{config[:cmd_pat]}/ } if config[:cmd_pat]
procs.select! { |p| p[:vsz].to_f > config[:vsz] } if config[:vsz]
# Ensure RSS is over this value
procs.select! { |p| p[:rss].to_f > config[:rss] } if config[:rss]
# Ensure RSS is under this value
procs.select! { |p| p[:over_rss].to_f < config[:over_rss] } if config[:over_rss]
procs.select! { |p| p[:cpu].to_f > config[:cpu_utilization] } if config[:cpu_utilization]
procs.select! { |p| p[:thcount].to_i > config[:thcount] } if config[:thcount]
procs.reject! { |p| etime_to_esec(p[:etime]) >= config[:esec_under] } if config[:esec_under]
Expand All @@ -277,6 +289,7 @@ def run
msg += "; user #{config[:user].join(',')}" if config[:user]
msg += "; vsz > #{config[:vsz]}" if config[:vsz]
msg += "; rss > #{config[:rss]}" if config[:rss]
msg += "; rss < #{config[:over_rss]}" if config[:over_rss]
msg += "; cpu > #{config[:cpu_utilization]}" if config[:cpu_utilization]
msg += "; thcount > #{config[:thcount]}" if config[:thcount]
msg += "; esec < #{config[:esec_under]}" if config[:esec_under]
Expand All @@ -287,7 +300,7 @@ def run

if config[:metric]
# #YELLOW
count = procs.map { |p| p[config[:metric]].to_i }.reduce { |a, b| a + b } # rubocop:disable SingleLineBlockParams
count = procs.map { |p| p[config[:metric]].to_i }.reduce { |a, e| a + e }
msg += "; #{config[:metric]} == #{count}"
else
count = procs.size
Expand Down

0 comments on commit 13f4dd8

Please sign in to comment.