From d2c37dde6f61dfad308b6f160a2dc211c64b0d62 Mon Sep 17 00:00:00 2001 From: Michalek Date: Tue, 16 Mar 2021 16:19:13 +0100 Subject: [PATCH] check-disk-usage.rb - Option to define minimal free space threshold --- CHANGELOG.md | 2 ++ README.md | 1 + bin/check-disk-usage.rb | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 380b3ad..f9ee97b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 9ab017a..23186d6 100644 --- a/README.md +++ b/README.md @@ -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** diff --git a/bin/check-disk-usage.rb b/bin/check-disk-usage.rb index 31bd4f0..5d464fc 100755 --- a/bin/check-disk-usage.rb +++ b/bin/check-disk-usage.rb @@ -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: 10_000 + # Setup variables # def initialize @@ -195,6 +202,8 @@ def check_mount(line) used = to_human(fs_info.bytes_used) total = to_human(fs_info.bytes_total) + return unless (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