Support Support Downloads Knowledge Base Juniper Support Portal Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

[EX/QFX] Understanding the SNMP stats-cache-lifetime option

0

0

Article ID: KB37386 KB Last Updated: 11 Sep 2021Version: 1.0
Summary:

This article describes the behavior of enabling stats-cache-lifetime option from SNMP configuration. It explains why the result of SNMP queries does not get updated for a certain time from OID.

Symptoms:

While doing SNMP query for OID, the returned value might not get updated for a certain period.

For example, use SNMP to get interface ingress unicast input byte count. It shows the value is not changed for some time though there are real time traffic.

Given the following SNMP configuration on the device:
snmp {
stats-cache-lifetime 20; 
community test {
    authorization read-only;
    clients {
        10.85.180.92/32;
    }
}


Note:  stats-cache-lifetime is a hidden option. Manually type full keyword to complete the configuration.

Run the following script on the SNMP server. It will send queries every 5 seconds to get interface (which snmp index is 708) ingress Unicast byte count:

while true; do date; snmpget -v2c -c test 10.85.172.27 1.3.6.1.2.1.2.2.1.11.708; sleep 5; done

Results retrieved from the target device:

[root@localhost ~]# sh snmpget.sh
Thu Aug 5 15:04:00 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2911777945
Thu Aug 5 15:04:05 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2911777945
Thu Aug 5 15:04:10 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2911777945
Thu Aug 5 15:04:15 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2911777945
Thu Aug 5 15:04:20 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2947538499
Thu Aug 5 15:04:25 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2947538499
Thu Aug 5 15:04:30 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2947538499
Thu Aug 5 15:04:35 PDT 2021
IF-MIB::ifInUcastPkts.708 = Counter32: 2947538499
 
The output above shows the polling result is only updated every 20 seconds.
Cause:

Enabling stats-cache-lifetime option:

Junos OS provides an option to configure the length of time (in seconds) that the interface stats is cached. If the NMS queries for the same interface again within the cache time, the same data is returned. If the NMS queries after the cache time, the cache is no longer valid and fresh data is fetched from the lower layers and the cache timestamp is updated. The default value for stats-cache-lifetime option is 5 seconds. This can be tuned as per the polling frequency. Because stats-cache-lifetime is configured as 20 seconds, there is no update for the polling OID during the configured period.  Since the poller sends queries every 5 seconds, the same query result is seen 4 times from the above example.

Solution:

There are two ways to consider whether an updated value needs to be retrieved from the kernel from every SNMP query:

  1. Adjust the stats-cache-lifetime and polling interval to make sure the polling interval value is no less than the stats-cache-lifetime.

    For example, modify the polling interval to 30 seconds from the script in the SNMP server side, but keep the stats-cache-lifetime configuration as 20 without change.

    while true; do date; snmpget -v2c -c test 10.85.172.27 1.3.6.1.2.1.2.2.1.11.708; sleep 30; done
     

    The following output shows the value is updated every time from each SNMP query:

    [root@localhost ~]# sh snmpget.sh
    Thu Aug  5 15:30:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1488250377
    Thu Aug  5 15:31:24 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1541845712
    Thu Aug  5 15:31:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1595415927
    Thu Aug  5 15:32:24 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1649006789
    Thu Aug  5 15:32:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1702629916
    Thu Aug  5 15:33:24 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1756252443
    Thu Aug  5 15:33:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1809855671
    Thu Aug  5 15:34:24 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1863440112
    Thu Aug  5 15:34:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1917046451
    Thu Aug  5 15:35:24 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 1970643345
    Thu Aug  5 15:35:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 2024274768
    Thu Aug  5 15:36:24 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 2077904802
    Thu Aug  5 15:36:54 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 2131493586

     
  2. Completely disable caching in mib2d by setting stats-cache-lifetime with zero and keep the polling interval as 5 seconds.

    # set snmp stats-cache-lifetime 0

    Note: Reducing the value of the stats-cache-lifetime option results in more queries and can impact performance. To get the live uncached statistics, set the value of the stats-cache-lifetime option to 0. However, this is not recommended since it completely disables the caching feature and impacts performance.

    The following output shows the value is updated every time from each SNMP query as expected:

    [root@localhost ~]# sh snmpget.sh
    Thu Aug  5 15:50:37 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3594877215
    Thu Aug  5 15:50:42 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3603819112
    Thu Aug  5 15:50:47 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3612739986
    Thu Aug  5 15:50:52 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3621688060
    Thu Aug  5 15:50:57 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3630680026
    Thu Aug  5 15:51:02 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3639590514
    Thu Aug  5 15:51:07 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3648533124
    Thu Aug  5 15:51:12 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3657442836
    Thu Aug  5 15:51:17 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3668161876
    Thu Aug  5 15:51:22 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3677107158
    Thu Aug  5 15:51:27 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3686044631
    Thu Aug  5 15:51:32 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3694985254
    Thu Aug  5 15:51:37 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3703925890
    Thu Aug  5 15:51:42 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3712849523
    Thu Aug  5 15:51:47 PDT 2021
    IF-MIB::ifInUcastPkts.708 = Counter32: 3721758306
Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search