How to Monitor Swap Space with net-snmp

Procedure

  1. Determine how much total swap space is available on your server (any of these methods will work):
    • RHEL:
      
      % free
                   total       used       free     shared    buffers     cached
      Mem:       1922236    1798148     124088          0     220632    1184504
      -/+ buffers/cache:     393012    1529224
      Swap:     16383992          0   16383992
      
      
      
      % cat /proc/swaps
      Filename                                Type            Size    Used    Priority
      /dev/sda3                               partition       16383992        0       -1
      
      
      
      % snmpwalk -c public -v2c highgate HOST-RESOURCES-MIB::hrStorageDescr
      HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Physical memory
      HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Virtual memory
      HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: Memory buffers
      HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: Cached memory
      HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: Swap space
      HOST-RESOURCES-MIB::hrStorageDescr.31 = STRING: /
      HOST-RESOURCES-MIB::hrStorageDescr.35 = STRING: /dev/shm
      HOST-RESOURCES-MIB::hrStorageDescr.36 = STRING: /boot
      HOST-RESOURCES-MIB::hrStorageDescr.37 = STRING: /opt
      HOST-RESOURCES-MIB::hrStorageDescr.38 = STRING: /tmp
      HOST-RESOURCES-MIB::hrStorageDescr.39 = STRING: /usr
      HOST-RESOURCES-MIB::hrStorageDescr.40 = STRING: /var
      HOST-RESOURCES-MIB::hrStorageDescr.42 = STRING: /var/tmp
      
      % snmpwalk -c public -v2c highgate HOST-RESOURCES-MIB::hrStorageSize.10
      HOST-RESOURCES-MIB::hrStorageSize.10 = INTEGER: 16383992
      
      
      
  2. net-snmp requires us to configure the minimum amount of swap space that needs to be available (below which it sends a trap):
    
    swap MIN
        monitors the amount of swap space available on the local system. If this falls
    below the specified threshold (MIN kB), then the memErrorSwap object will be set to 1,
    and a suitable description message reported via memSwapErrorMsg.
    
            Note:
                This situation will not automatically trigger a trap to report the problem
    - see the DisMan Event MIB section later. 
    
        If this directive is not specified, the default threshold is 16 MB. 
    
    

    As a local rule of thumb, assume we want an alert if < 15% of swap space is free:

    
    16383992 bytes * 15% threshold factor = 2457599 bytes
    2457599 bytes * 1 kB/1000 bytes = 2458 kB
    
    
  3. Add a swap entry to snmpd.conf:
    
    swap 2458
    
    
  4. Restart snmpd:
    
    % sudo /etc/init.d/snmpd restart
    Stopping snmpd:                                            [  OK  ]
    Starting snmpd:                                            [  OK  ]