Blame SOURCES/net-snmp-5.7.2-counter64.patch

4afbb4
From 0dc151a72ce495d3d94704efba609505e465292b Mon Sep 17 00:00:00 2001
4afbb4
From: Niels Baggesen <nba@users.sourceforge.net>
4afbb4
Date: Mon, 13 Jun 2016 16:50:08 +0200
4afbb4
Subject: [PATCH] UCD-SNMP-MIB: Add 64-bit memory objects for large servers.
4afbb4
4afbb4
---
4afbb4
 agent/mibgroup/ucd-snmp/memory.c | 100 ++++++++++++++++++++++++--
4afbb4
 agent/mibgroup/ucd-snmp/memory.h |   9 +++
4afbb4
 mibs/UCD-SNMP-MIB.txt            | 116 ++++++++++++++++++++++++++++++-
4afbb4
 3 files changed, 220 insertions(+), 5 deletions(-)
4afbb4
4afbb4
diff --git a/agent/mibgroup/ucd-snmp/memory.c b/agent/mibgroup/ucd-snmp/memory.c
4afbb4
index 742186f3a..a7f060a50 100644
4afbb4
--- a/agent/mibgroup/ucd-snmp/memory.c
4afbb4
+++ b/agent/mibgroup/ucd-snmp/memory.c
4afbb4
@@ -26,7 +26,7 @@ init_memory(void)
4afbb4
         netsnmp_create_handler_registration("memory", handle_memory,
4afbb4
                                  memory_oid, OID_LENGTH(memory_oid),
4afbb4
                                              HANDLER_CAN_RONLY),
4afbb4
-                                 1, 17);
4afbb4
+                                 1, 26);
4afbb4
     netsnmp_register_scalar(
4afbb4
         netsnmp_create_handler_registration("memSwapError", handle_memory,
4afbb4
                            memSwapError_oid, OID_LENGTH(memSwapError_oid),
4afbb4
@@ -59,7 +59,9 @@ handle_memory(netsnmp_mib_handler *handler,
4afbb4
                 netsnmp_request_info *requests)
4afbb4
 {
4afbb4
     netsnmp_memory_info *mem_info;
4afbb4
-    int val;
4afbb4
+    unsigned long val;
4afbb4
+    struct counter64 c64;
4afbb4
+    int type = ASN_INTEGER;
4afbb4
     char buf[1024];
4afbb4
 
4afbb4
     /*
4afbb4
@@ -184,6 +186,92 @@ handle_memory(netsnmp_mib_handler *handler,
4afbb4
             val  = (mem_info->size - mem_info->free);      /* cached */
4afbb4
             val *= (mem_info->units/1024);
4afbb4
             break;
4afbb4
+	case MEMORY_SWAP_TOTAL_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->size;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_SWAP_AVAIL_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->free;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_REAL_TOTAL_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->size;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_REAL_AVAIL_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->free;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_SWAP_MIN_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+	    val = minimum_swap;
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_FREE_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->free;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_SHARED_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SHARED, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->size;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_BUFFER_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_MBUF, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->size - mem_info->free;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
+	case MEMORY_CACHED_X:
4afbb4
+	    type = ASN_COUNTER64;
4afbb4
+            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_CACHED, 0 );
4afbb4
+            if (!mem_info)
4afbb4
+               goto NOSUCH;
4afbb4
+            val  = mem_info->size - mem_info->free;
4afbb4
+            val *= (mem_info->units/1024);
4afbb4
+	    c64.low = val & 0xFFFFFFFF;
4afbb4
+	    c64.high = val >>32;
4afbb4
+            break;
4afbb4
         case MEMORY_SWAP_ERROR:
4afbb4
             mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
4afbb4
             if (!mem_info)
4afbb4
@@ -213,8 +301,12 @@ handle_memory(netsnmp_mib_handler *handler,
4afbb4
          * All non-integer objects (and errors) have already been
4afbb4
          * processed.  So return the integer value.
4afbb4
          */
4afbb4
-        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
4afbb4
-                                 (u_char *)&val, sizeof(val));
4afbb4
+	if (type == ASN_INTEGER)
4afbb4
+	    snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
4afbb4
+				     (u_char *)&val, sizeof(val));
4afbb4
+	else
4afbb4
+	    snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER64,
4afbb4
+				     (u_char *)&c64, sizeof(c64));
4afbb4
         break;
4afbb4
 
4afbb4
     default:
4afbb4
diff --git a/agent/mibgroup/ucd-snmp/memory.h b/agent/mibgroup/ucd-snmp/memory.h
4afbb4
index a44d82e51..ded214022 100644
4afbb4
--- a/agent/mibgroup/ucd-snmp/memory.h
4afbb4
+++ b/agent/mibgroup/ucd-snmp/memory.h
4afbb4
@@ -32,6 +32,15 @@ Netsnmp_Node_Handler handle_memory;
4afbb4
 #define MEMORY_CACHED       15
4afbb4
 #define MEMORY_STXT_USED    16
4afbb4
 #define MEMORY_RTXT_USED    17
4afbb4
+#define MEMORY_SWAP_TOTAL_X 18
4afbb4
+#define MEMORY_SWAP_AVAIL_X 19
4afbb4
+#define MEMORY_REAL_TOTAL_X 20
4afbb4
+#define MEMORY_REAL_AVAIL_X 21
4afbb4
+#define MEMORY_FREE_X       22
4afbb4
+#define MEMORY_SWAP_MIN_X   23
4afbb4
+#define MEMORY_SHARED_X     24
4afbb4
+#define MEMORY_BUFFER_X     25
4afbb4
+#define MEMORY_CACHED_X     26
4afbb4
 #define MEMORY_SWAP_ERROR  100
4afbb4
 #define MEMORY_SWAP_ERRMSG 101
4afbb4
 #endif                          /* MEMORY_H */
4afbb4
diff --git a/mibs/UCD-SNMP-MIB.txt b/mibs/UCD-SNMP-MIB.txt
4afbb4
index e8acc8c0d..cde67feb5 100644
4afbb4
--- a/mibs/UCD-SNMP-MIB.txt
4afbb4
+++ b/mibs/UCD-SNMP-MIB.txt
4afbb4
@@ -33,11 +33,14 @@ IMPORTS
4afbb4
     Integer32, Opaque, enterprises, Counter32, Unsigned32
4afbb4
         FROM SNMPv2-SMI
4afbb4
 
4afbb4
+    CounterBasedGauge64
4afbb4
+        FROM HCNUM-TC
4afbb4
+
4afbb4
     TEXTUAL-CONVENTION, DisplayString, TruthValue
4afbb4
 	FROM SNMPv2-TC;
4afbb4
 
4afbb4
 ucdavis MODULE-IDENTITY
4afbb4
-    LAST-UPDATED "200901190000Z"
4afbb4
+    LAST-UPDATED "201606100000Z"
4afbb4
     ORGANIZATION "University of California, Davis"
4afbb4
     CONTACT-INFO    
4afbb4
 	"This mib is no longer being maintained by the University of
4afbb4
@@ -55,6 +58,10 @@ ucdavis MODULE-IDENTITY
4afbb4
     DESCRIPTION
4afbb4
 	"This file defines the private UCD SNMP MIB extensions."
4afbb4
 
4afbb4
+    REVISION	 "201606100000Z"
4afbb4
+    DESCRIPTION
4afbb4
+	"New 64-bit memory objects"
4afbb4
+
4afbb4
     REVISION	 "201105140000Z"
4afbb4
     DESCRIPTION
4afbb4
 	"New objects for monitoring CPU Steal, Guest and Nice values"
4afbb4
@@ -629,6 +636,113 @@ memUsedRealTXT OBJECT-TYPE
4afbb4
          pages from other uses of physical memory."
4afbb4
     ::= { memory 17 }
4afbb4
 
4afbb4
+memTotalSwapX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+	"The total amount of swap space configured for this host."
4afbb4
+    ::= { memory 18 }
4afbb4
+
4afbb4
+memAvailSwapX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+	"The amount of swap space currently unused or available."
4afbb4
+    ::= { memory 19 }
4afbb4
+
4afbb4
+memTotalRealX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+	"The total amount of real/physical memory installed
4afbb4
+         on this host."
4afbb4
+    ::= { memory 20 }
4afbb4
+
4afbb4
+memAvailRealX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+	"The amount of real/physical memory currently unused
4afbb4
+         or available."
4afbb4
+    ::= { memory 21 }
4afbb4
+
4afbb4
+
4afbb4
+memTotalFreeX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+        "The total amount of memory free or available for use on
4afbb4
+         this host.  This value typically covers both real memory
4afbb4
+         and swap space or virtual memory."
4afbb4
+    ::= { memory 22 }
4afbb4
+
4afbb4
+memMinimumSwapX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+	"The minimum amount of swap space expected to be kept
4afbb4
+         free or available during normal operation of this host.
4afbb4
+
4afbb4
+         If this value (as reported by 'memAvailSwap(4)') falls
4afbb4
+         below the specified level, then 'memSwapError(100)' will
4afbb4
+         be set to 1 and an error message made available via
4afbb4
+         'memSwapErrorMsg(101)'."
4afbb4
+    ::= { memory 23 }
4afbb4
+
4afbb4
+memSharedX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+        "The total amount of real or virtual memory currently
4afbb4
+         allocated for use as shared memory.
4afbb4
+
4afbb4
+         This object will not be implemented on hosts where the
4afbb4
+         underlying operating system does not explicitly identify
4afbb4
+         memory as specifically reserved for this purpose."
4afbb4
+    ::= { memory 24 }
4afbb4
+
4afbb4
+memBufferX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+        "The total amount of real or virtual memory currently
4afbb4
+         allocated for use as memory buffers.
4afbb4
+
4afbb4
+         This object will not be implemented on hosts where the
4afbb4
+         underlying operating system does not explicitly identify
4afbb4
+         memory as specifically reserved for this purpose."
4afbb4
+    ::= { memory 25 }
4afbb4
+
4afbb4
+memCachedX OBJECT-TYPE
4afbb4
+    SYNTAX	CounterBasedGauge64
4afbb4
+    UNITS       "kB"
4afbb4
+    MAX-ACCESS	read-only
4afbb4
+    STATUS	current
4afbb4
+    DESCRIPTION
4afbb4
+        "The total amount of real or virtual memory currently
4afbb4
+         allocated for use as cached memory.
4afbb4
+
4afbb4
+         This object will not be implemented on hosts where the
4afbb4
+         underlying operating system does not explicitly identify
4afbb4
+         memory as specifically reserved for this purpose."
4afbb4
+    ::= { memory 26 }
4afbb4
+
4afbb4
 memSwapError OBJECT-TYPE
4afbb4
     SYNTAX	UCDErrorFlag
4afbb4
     MAX-ACCESS	read-only
4afbb4