Skip to content

Commit

Permalink
check-disk-usage.rb - Option to define minimal free space threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
VeselaHouba committed Mar 16, 2021
1 parent 9fb504d commit d84c7e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
### Added
- `check-disk-usage.rb` - Option to define minimal free space threshold.

## [5.1.4] - 2020-11-05
### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Usage: check-disk-usage.rb (options)
-m MAGIC Magic factor to adjust warn/crit thresholds. Example: .9
-l MINIMUM Minimum size to adjust (in GB)
-n NORMAL Levels are not adapted for filesystems of exactly this size, where levels are reduced for smaller filesystems and raised for larger filesystems.
-f FREESPACEBELOW Trigger warn/critical alarm only if free space on mount goes below this threshold (in GB). Useful on huge filesystems which are 99.X percent full and still have lots of space left.
```

**metrics-disk-usage.rb**
Expand Down
17 changes: 13 additions & 4 deletions bin/check-disk-usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ class CheckDisk < Sensu::Plugin::Check::CLI
proc: proc(&:to_f),
default: 100

option :freespacebelow,
short: '-f FREESPACEBELOW',
description: 'Trigger alarm only if free space on device is below '\
'this threshold (in GB)',
proc: proc(&:to_f),
default: 10000

# Setup variables
#
def initialize
Expand Down Expand Up @@ -195,10 +202,12 @@ def check_mount(line)
used = to_human(fs_info.bytes_used)
total = to_human(fs_info.bytes_total)

if percent_b >= bcrit
@crit_fs << "#{line.mount_point} #{percent_b}% bytes usage (#{used}/#{total})"
elsif percent_b >= bwarn
@warn_fs << "#{line.mount_point} #{percent_b}% bytes usage (#{used}/#{total})"
if (fs_info.bytes_total - fs_info.bytes_used) <= (config[:freespacebelow] * 1_000_000_000)
if percent_b >= bcrit
@crit_fs << "#{line.mount_point} #{percent_b}% bytes usage (#{used}/#{total})"
elsif percent_b >= bwarn
@warn_fs << "#{line.mount_point} #{percent_b}% bytes usage (#{used}/#{total})"
end
end
end

Expand Down

0 comments on commit d84c7e4

Please sign in to comment.