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 isn't using reserved blocks in calculation #151

Closed pbrzica closed 4 years ago

pbrzica commented 4 years ago

OS:

$ cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

Ruby:

$ /opt/sensu/embedded/bin/ruby --version
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]

Sensu:

$ /opt/sensu/embedded/bin/sensu-client --version
1.9.0

Issue: check-disk-usage.rb reports disk usage at 75% and df -h reports disk usage at 80%. Is there any way to get the check to account for system reserved blocks as well?

nixwiz commented 4 years ago

The plugin currently uses the bytes_free from filesystem.stat which does not factor in privileged access (reserved). filesystem.stat does also surface bytes_available that Returns the amount of free space available to unprivileged processes.. However, changing the default behavior at this point in the plugin's lifecycle, is inadvisable.

If you would like to offer up a PR with a new command line option to use bytes_available instead, that would be acceptable.

VeselaHouba commented 4 years ago

That's odd. I use the sensu-go asset and it depends on which ruby I use to run the script. I've added following lines to script

    free = to_human(fs_info.bytes_free)
    printf("%s used: %s free: %s total: %s\n",line.mount_point,used,free,total)

The "old" sensu embedded ruby works as expected: Doesn't count in privileged.

/opt/sensu/embedded/bin/ruby --version
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]

/opt/sensu/embedded/bin/ruby /var/cache/sensu/sensu-agent/0253c3eb83ca95ef21c1aede03f8e7ec80431a1e363246a4eb4c9b6e2d619060f1d06f6c11eef107e7eb8bd9b16be236ca53120839255362699ed4c05644d596/lib/ruby/2.4.0/bundler/gems/sensu-plugins-disk-checks-0bd87037cbdb/bin/check-disk-usage.rb |grep snapsh
/snapshots used: 980.25 GiB free: 3.06 GiB total: 983.30 GiB
CheckDisk CRITICAL: /snapshots 99.69% bytes usage (980.25 GiB/983.30 GiB)

But the output of the same script output in sensu-go Web GUI is not correct. Looks like the ruby from ruby runtime-asset https://bonsai.sensu.io/assets/sensu/sensu-ruby-runtime actually works with privileged bytes as if it was normal bytes.

# ruby runtime asset
 /var/cache/sensu/sensu-agent/a28952fd93fc63db1f8988c7bc40b0ad815eb9f35ef7317d6caf5d77ecfbfd824a9db54184400aa0c81c29b34cb48c7e8c6e3f17891aaf84cafa3c134266a61a/bin/ruby --version
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-linux]
/snapshots used: 930.23 GiB free: 53.07 GiB total: 983.30 GiB
CheckDisk OK: All disk usage under 75% and inode usage under 85%

@nixwiz I can't find any mention of bytes_available in Filesystem.stat docu, https://www.rubydoc.info/gems/sys-filesystem/1.1.4/Sys/Filesystem/Stat , can you point me to your source please?

VeselaHouba commented 4 years ago

Please ignore the request about docu. I was checking old version. https://www.rubydoc.info/gems/sys-filesystem/Sys/Filesystem/Stat PR is on the way.