sensu-plugins / sensu-plugins-disk-checks

This plugin provides native disk instrumentation for monitoring and metrics collection, including: health, usage, and various metrics.
http://sensu-plugins.io
MIT License
27 stars 63 forks source link

check-disk-usage.rb doesn't match df -h Use% #156

Closed SaviourSelf closed 4 years ago

SaviourSelf commented 4 years ago

I use the df -h Use% in other reporting, but alert on sensu check-disk-usage.rb percentages.

Looks like there was a fix that added an option to ignore privileged bytes here: https://github.com/sensu-plugins/sensu-plugins-disk-checks/commit/56f640ade91819ff59f0e242a1f088b9f9a52e4d

I tried adding the -r flag, and the value was off by a couple percent.

Is this line supposed to reflect the df -h used percentage? https://github.com/sensu-plugins/sensu-plugins-disk-checks/blob/master/bin/check-disk-usage.rb#L213

I ran a test:

Filesystem      Size  Used Avail Use% Mounted on
rootfs          448G  144G  319G  32% /

check-disk-usage.rb -w 25
CheckDisk WARNING:  /  29.66% bytes usage (144.56 GiB/487.42 GiB)

check-disk-usage.rb -w 25 -r
CheckDisk WARNING:  /  34.76% bytes usage (144.65 GiB/487.42 GiB)

I looked into the df function for calculating the Use percentage. Looks like the following function might work:

2.6.3 :001 > used = 144
 => 144
2.6.3 :002 > available = 319
 => 319
2.6.3 :003 > (used * 100.0) / (used + available) + (((used * 100) % (used + available) != 0) ? 1 : 0)
 => 32.101511879049674

See: https://github.com/coreutils/coreutils/blob/master/src/df.c#L1172-L1174

Can this script be adjusted to reflect the df Use% ?

majormoses commented 4 years ago

fixed in #157 see the PR for a link to the released version once that has been created.