How to set the net-snmp agent update or counter refresh interval

Submitted by admin on Sun, 01/16/2011 - 15:58

From my experience I know that it's pretty common in all kinds of network equipment as switches, routers etc, to update snmp agent counters (OID's) in real time. It was kind of a surprise when I found out, while testing my own products, that net-snmp uses different agent update intervals for different mib-tree branches.

I noticed that for example (on my Ubuntu 10.04 LTS box) the "ifTable" branch was updated every 15 and the "ip" branch every 5 seconds by default. See the screenshot below of the eth0 interface of my Linux box polled every second. As you can see it's only a spike every 15 seconds.

It depends of course on your monitoring method whether a 15 seconds update interval suits your needs but in my case it did not and I decided to start "googling" in order to find out how I could modify this behavior. After some digging I found what I was looking for. Here's how you can change the update intervals.

The net-snmp-agent.mib contains a table called "nsCacheTable (1.3.6.1.4.1.8072.1.5.3) which contains entries describing - quoting from the mib - "The length of time (?in seconds) for which the data in this particular cache entry will remain valid.". In my case (default net-snmp installation) the table contained 30 entries. Below is a screen-dump of the nsCacheTable of my Linux box.

The first row of the table holds the "cache timeout" (15 seconds) of the interfaces table (ifTable - 1.3.6.1.2.1.2.2). The second row configures the cache-timeout (5 seconds) of the "ip" table. Below is a fragment from the net-snmp-agent describing the child-nodes of the nsCacheEntry node:

nsCachedOID     OBJECT-TYPE
    SYNTAX      OBJECT IDENTIFIER
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION
      "The root OID of the data being cached."
    ::= { nsCacheEntry 1 }

nsCacheTimeout  OBJECT-TYPE
    SYNTAX      INTEGER
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION
      "The length of time (?in seconds) for which the data in
       this particular cache entry will remain valid." 
    ::= { nsCacheEntry 2 }

nsCacheStatus   OBJECT-TYPE
    SYNTAX      NetsnmpCacheStatus
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION
      "The current status of this particular cache entry.
       Acceptable values for Set requests are 'enabled(1)',
       'disabled(2)' or 'empty(3)' (to clear all cached data).
       Requests to read the value of such an object will
       return 'disabled(2)' through to 'expired(5)'."
    ::= { nsCacheEntry 3 }

The syntax of the nsCacheTimeout field is INTEGER and offers read-write access! I decided to give this a try and use the net-SNMP snmpset command to modify the nsCacheTimeout value for the "ifTable" on my Linux box.

snmpset -c private -v 1 192.168.3.253 1.3.6.1.4.1.8072.1.5.3.1.2.1.3.6.1.2.1.2.2 i 1

After this the graph of the load on my server's eth0 interface (polled every second) showed:

Using the FC-RTSet component to modify the nsCacheTimeout value

FC_RTSet (part of the FineConnection SNMP Components) makes it very easy to modify the nsCacheTimeout value for a mib table. Below is a screen-shot of the FC_RTSet component and the corresponding xml config file. Be aware that because the nsCacheTimeout node is not part of the mib-2 branch, you need a license to get FC_RTSet working.

And of course the configuration xml file...

<?xml version="1.0"?>
<rtset>
<programtitle>Set nsCacheTimeout</programtitle>
 <left></left>
 <top></top>
 <allowemptyfieldvalues>false</allowemptyfieldvalues>
 <hosttablefilename></hosttablefilename>
 <shooter>
  <shootertargettable>
   <shootertargetentry>
    <oid>1.3.6.1.4.1.8072.1.5.3.1.2</oid>
    <instance>on runtime</instance>
   </shootertargetentry>
  </shootertargettable>
 </shooter>
 <hoststable>
  <hostentry>
    <host>192.168.3.253</host>
    <community>private</community>
    <snmpversion>1</snmpversion>
    <snmpport></snmpport>
    <username></username>
    <authpw></authpw>
    <encalg></encalg>
    <encpw></encpw>
  </hostentry>
 </hoststable>
 <oidtable>
  <oidentry>
   <oid>1.3.6.1.4.1.8072.1.5.3.1.2</oid>
   <oiddescr>nscacheTimeout</oiddescr>
   <oidtype>integer</oidtype>
  </oidentry>
 </oidtable>
 <vendorspecific>
   <vlogofile></vlogofile>
   <vappname></vappname>
   <vappversion></vappversion>
 </vendorspecific>
</rtset>

Additional observation

If the net-snmp daemon (snmpd) is restarted (or the system is booted) all update intervals return to their default values. So far I haven't found a way to save the modified update values through snmp! The only way now is by running a bash script that sets the update intervals after the launch of the snmp daemon.

Paul van Bergen

© 2000-2012 FineConnection. Drupal theme by Kiwi Themes.