Skip to content

Adding snmp support for memory and mount points#379

Open
rsh2prasad wants to merge 1 commit into
sonic-net:masterfrom
rsh2prasad:rakprasa/snmp_mem_mnt_stats
Open

Adding snmp support for memory and mount points#379
rsh2prasad wants to merge 1 commit into
sonic-net:masterfrom
rsh2prasad:rakprasa/snmp_mem_mnt_stats

Conversation

@rsh2prasad

@rsh2prasad rsh2prasad commented Jun 9, 2026

Copy link
Copy Markdown

Why I did it

This PR adds support for HOST-RESOURCES-MIB (RFC 2790 - hrStorageTable (.1.3.6.1.2.1.25.2.3) and hrFSTable (.1.3.6.1.2.1.25.3.8) to monitor disk usage, filesystem inventory, and memory utilization on devices), sourcing data from the new MOUNT_POINTS|* and MEMORY_STATS|* tables that procdockerstatsd (sonic-host-services) writes to STATE_DB.

This PR depends on the corresponding sonic-host-services change that populates those STATE_DB tables. sonic-net/sonic-host-services#392

How I did it

Added a new MIB module src/sonic_ax_impl/mibs/ietf/rfc2790.py and registered its tables in SonicMIB:

  • hrStorageTable (.1.3.6.1.2.1.25.2.3) via hrStorageHandler

    • hrStorageDescr (1.3) – filesystem source from MOUNT_POINTS|*.Filesystem; falls back to <key> Memory for MEMORY_STATS|* rows.
    • hrStorageAllocationUnits (1.4) – fixed at 1024 (data is reported in 1K blocks).
    • hrStorageSize (1.5) – 1K-blocks field, returned as integer units of allocation.
    • hrStorageUsed (1.6) – Used field.
  • hrFSTable (.1.3.6.1.2.1.25.3.8) via fsHandler

    • hrFSMountPoint (1.2) – mount path parsed from the STATE_DB key (empty string for MEMORY_STATS rows, which are not real filesystems).
    • hrFSType (1.4) – filesystem type from MOUNT_POINTS|*.Type.
  • Data source / lifecycle

    • On init and on every fresh SNMP walk (get_next with no sub_id), the handlers re-read MOUNT_POINTS|* and MEMORY_STATS|* keys from STATE_DB, drop entries that return no data, sort mount-point entries, and append memory entries so indexing is stable within a walk.
    • All STATE_DB access goes through a small _db_call helper that catches exceptions and logs them, so a transient Redis hiccup cannot crash the SNMP agent.
    • Defensive logging when tables are missing/empty (helps diagnose host-services not running or out of sync).
  • Registration in src/sonic_ax_impl/main.py: imported rfc2790 and added rfc2790.hrStorageTable and rfc2790.hrFSTable to the SonicMIB class hierarchy.

How to verify it

  • Unit tests added (~2,180 new lines):
    • tests/test_rfc2790_hrstorage.pyhrStorageTable OID walks, value types, allocation units, descriptions (including memory fallback), and out-of-range indexing.
    • tests/test_rfc2790_fs.pyhrFSTable mount-point and type retrieval, including the empty-mount behavior for memory rows.
    • tests/test_rfc2790_empty_tables.py – behavior when MOUNT_POINTS and/or MEMORY_STATS are empty or missing in STATE_DB, ensuring no exceptions and graceful None returns.
    • Mock data added to tests/mock_tables/state_db.json covering both tables.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

Signed-off-by: rakprasa <rsh2prasad@gmail.com>
@rsh2prasad rsh2prasad force-pushed the rakprasa/snmp_mem_mnt_stats branch from b9359d2 to 2d4b68d Compare June 18, 2026 17:08
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@rsh2prasad rsh2prasad marked this pull request as ready for review June 18, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants