Skip to content

Commit

Permalink
closes #6 (#10)
Browse files Browse the repository at this point in the history
While this change is not a major code change it is a major change in default behavior. This attempts to have more 'sane' defaults. For a more in depth explanation on the rationale please see: #6 (comment)
  • Loading branch information
majormoses authored and sstarcher committed Sep 20, 2016
1 parent 5a3cf10 commit 1fb4b29
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Changed
- bin/check-load.rb change the default of per_core to true
- bin/check-load.rb change the default thresholds to better align with per_core values
- bin/check-load.rb changes to use >= rather than > for thresholds
- bin/check-load.rb switch to using 'unknown' rather than 'warning' when unable to determine the load average

## [1.0.0] - 2016-06-16
### Changed
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@

## Usage

### check-load.rb

To see the list of full options you can run:
```
$ ./bin/check-load.rb --help
Usage: ./bin/check-load.rb (options)
-c, --crit L1,L5,L15 Load CRITICAL threshold, 1/5/15 min average
-p, --per-core Divide load average results by cpu/core count
-w, --warn L1,L5,L15 Load WARNING threshold, 1/5/15 min average
```

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.


## Installation

[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
Expand Down
14 changes: 7 additions & 7 deletions bin/check-load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# gem: sensu-plugin
#
# USAGE:
#
# ./bin/check-load.rb --help
# NOTES:
#
# LICENSE:
Expand All @@ -26,7 +26,7 @@
require 'sensu-plugin/check/cli'

class LoadAverage
def initialize(per_core = false)
def initialize(per_core = true)
@cores = per_core ? cpu_count : 1
@avg = File.read('/proc/loadavg').split.take(3).map { |a| (a.to_f / @cores).round(2) } rescue nil # rubocop:disable RescueModifier
end
Expand All @@ -42,7 +42,7 @@ def failed?
end

def exceed?(thresholds)
@avg.zip(thresholds).any? { |a, t| a > t }
@avg.zip(thresholds).any? { |a, t| a >= t }
end

def to_s
Expand All @@ -56,25 +56,25 @@ class CheckLoad < Sensu::Plugin::Check::CLI
long: '--warn L1,L5,L15',
description: 'Load WARNING threshold, 1/5/15 min average',
proc: proc { |a| a.split(',').map(&:to_f) },
default: [10, 20, 30]
default: [2.75, 2.5, 2.0]

option :crit,
short: '-c L1,L5,L15',
long: '--crit L1,L5,L15',
description: 'Load CRITICAL threshold, 1/5/15 min average',
proc: proc { |a| a.split(',').map(&:to_f) },
default: [25, 50, 75]
default: [3.5, 3.25, 3.0]

option :per_core,
short: '-p',
long: '--per-core',
description: 'Divide load average results by cpu/core count',
boolean: 'true',
default: false
default: true

def run
avg = LoadAverage.new(config[:per_core])
warning 'Could not read load average from /proc' if avg.failed?
unknown 'Could not read load average from /proc' if avg.failed?
message "Load average: #{avg}"
critical if avg.exceed?(config[:crit])
warning if avg.exceed?(config[:warn])
Expand Down
2 changes: 1 addition & 1 deletion lib/sensu-plugins-load-checks/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SensuPluginsLoadChecks
module Version
MAJOR = 1
MAJOR = 2
MINOR = 0
PATCH = 0

Expand Down

0 comments on commit 1fb4b29

Please sign in to comment.