Skip to content

enh(snmp_standard::mode::diskusage): add 'auto' to --space-reservation - #6352

Open
saeroshi wants to merge 1 commit into
centreon:developfrom
saeroshi:enh-diskusage-space-reservation-auto
Open

enh(snmp_standard::mode::diskusage): add 'auto' to --space-reservation#6352
saeroshi wants to merge 1 commit into
centreon:developfrom
saeroshi:enh-diskusage-space-reservation-auto

Conversation

@saeroshi

Copy link
Copy Markdown

Community contributors

Description

--space-reservation only accepts a fixed percentage, applied identically to every partition. This is wrong as soon as a host mixes filesystems with different reservations, which is the common case: ext4 formatted with -m 5, ext4 with -m 0 on data volumes, xfs, tmpfs, nfs...

The UCD-SNMP-MIB already exposes dskAvail (f_bavail) right next to dskTotal and dskUsed, at the same index of the table this mode already walks. The real reservation of a partition is therefore dskTotal - dskUsed - dskAvail, which is exactly f_bfree - f_bavail.

This PR adds auto to --space-reservation to use that measured value. dskAvail OIDs are requested only when the option is set, so there is no extra SNMP traffic for existing users.

It aligns the SNMP mode with os::linux::local::mode::storage, where Total = Used + Available since #4978.

Three side effects worth mentioning:

  • fixed a division by zero when the reservation equals the total size (--space-reservation=100 currently exits UNKNOWN on "Illegal division by zero");
  • non-numeric values are now rejected explicitly instead of being silently evaluated as 0;
  • includeAllDisks was added to the spellcheck stopwords, as the POD spell check already failed on this file before this change.

Related to #386, which asked for this exact feature in 2016 (including the AUTO value) and was closed with "SNMP doesn't give the information about the root reservation". That is true for HOST-RESOURCES-MIB, but not for the dskTable this mode relies on.

Type of change

  • Patch fixing an issue (non-breaking change)
  • New functionality (non-breaking change)
  • Functionality enhancement or optimization (non-breaking change)
  • Breaking change (patch or feature) that might cause side effects breaking part of the Software

How this pull request can be tested ?

No new fixture is required: tests/os/linux/snmp/linux.snmpwalk already contains dskAvail, with / on ext4 (5.12% reserved) and four tmpfs (0%).

snmpsim-command-responder --logging-method=null \
  --agent-udpv4-endpoint=127.0.0.1:2024 --data-dir='./tests' &
robot tests/os/linux/snmp/disk-usage.robot
# 29 tests, 29 passed, 0 failed

Test cases 27, 28 and 29 were added (auto on all partitions, auto on / only, and rejection of an invalid value). Only / is affected by auto (7.04% -> 7.42%), the tmpfs partitions are left untouched, which is the point.

Also checked against a real net-snmp agent (Debian 12, includeAllDisks 10%), compared with df:

partition real reservation df no option =5 =auto
/ (ext4, -m 5) 5.22% 47.14% 44.68% 47.03% 47.14%
/data (ext4, -m 0) 0.32% 27.87% 27.78% 29.24% 27.87%

auto matches df on both partitions, which no single fixed percentage can do.

Checklist

  • I have followed the coding style guidelines provided by Centreon
  • I have commented my code, especially hard-to-understand areas of the PR.
  • I have rebased my development branch on the base branch (develop).
  • I have provide data or shown output displaying the result of this code in the plugin area concerned.

--space-reservation only accepted a fixed percentage applied to every
partition, which is wrong as soon as a host mixes filesystems with
different reservations (ext4 with -m 5, ext4 with -m 0, xfs, tmpfs...).

The UCD-SNMP-MIB already exposes dskAvail (f_bavail) next to dskTotal and
dskUsed, so the real reservation of each partition can be measured with
dskTotal - dskUsed - dskAvail (that is f_bfree - f_bavail).

Add 'auto' to --space-reservation to use that computation. dskAvail OIDs
are only requested when the option is set, so there is no extra SNMP
traffic for existing users.

This aligns the SNMP mode with os::linux::local::mode::storage, where
Total = Used + Available since centreon#4978.
@saeroshi
saeroshi requested review from a team as code owners August 12, 2026 14:32
@saeroshi
saeroshi requested review from bouda1, lucie-tirand and sechkem and removed request for a team August 12, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants