Linux subagent: added 64 bit interface counters (issue #1018)
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 29 Jun 2016 15:59:10 +0000 (18:59 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 29 Jun 2016 15:59:10 +0000 (18:59 +0300)
src/agent/subagents/linux/linux.cpp
src/agent/subagents/linux/linux_subagent.h
src/agent/subagents/linux/net.cpp

index efe8846..9157cb7 100644 (file)
@@ -183,28 +183,26 @@ static NETXMS_SUBAGENT_PARAM m_parameters[] =
        { _T("DRBD.Version.Protocol"),        H_DRBDVersion,     _T("p"),
                DCI_DT_STRING, _T("DRBD protocol version") },
 
-       { _T("Net.Interface.AdminStatus(*)"), H_NetIfInfoFromIOCTL, (TCHAR *)IF_INFO_ADMIN_STATUS,
-               DCI_DT_INT,             DCIDESC_NET_INTERFACE_ADMINSTATUS },
-       { _T("Net.Interface.BytesIn(*)"),     H_NetIfInfoFromProc, (TCHAR *)IF_INFO_BYTES_IN,
-               DCI_DT_UINT,    DCIDESC_NET_INTERFACE_BYTESIN },
-       { _T("Net.Interface.BytesOut(*)"),    H_NetIfInfoFromProc, (TCHAR *)IF_INFO_BYTES_OUT,
-               DCI_DT_UINT,    DCIDESC_NET_INTERFACE_BYTESOUT },
-       { _T("Net.Interface.Description(*)"), H_NetIfInfoFromIOCTL, (TCHAR *)IF_INFO_DESCRIPTION,
-               DCI_DT_STRING,  DCIDESC_NET_INTERFACE_DESCRIPTION },
-       { _T("Net.Interface.InErrors(*)"),    H_NetIfInfoFromProc, (TCHAR *)IF_INFO_IN_ERRORS,
-               DCI_DT_UINT,    DCIDESC_NET_INTERFACE_INERRORS },
-       { _T("Net.Interface.Link(*)"),        H_NetIfInfoFromIOCTL, (TCHAR *)IF_INFO_OPER_STATUS,
-               DCI_DT_INT,             DCIDESC_NET_INTERFACE_LINK },
-       { _T("Net.Interface.OutErrors(*)"),   H_NetIfInfoFromProc, (TCHAR *)IF_INFO_OUT_ERRORS,
-               DCI_DT_UINT,    DCIDESC_NET_INTERFACE_OUTERRORS },
-       { _T("Net.Interface.PacketsIn(*)"),   H_NetIfInfoFromProc, (TCHAR *)IF_INFO_PACKETS_IN,
-               DCI_DT_UINT,    DCIDESC_NET_INTERFACE_PACKETSIN },
-       { _T("Net.Interface.PacketsOut(*)"),  H_NetIfInfoFromProc, (TCHAR *)IF_INFO_PACKETS_OUT,
-               DCI_DT_UINT,    DCIDESC_NET_INTERFACE_PACKETSOUT },
-       { _T("Net.IP.Forwarding"),            H_NetIpForwarding, (TCHAR *)4,
-               DCI_DT_INT,             DCIDESC_NET_IP_FORWARDING },
-       { _T("Net.IP6.Forwarding"),           H_NetIpForwarding, (TCHAR *)6,
-               DCI_DT_INT,             DCIDESC_NET_IP6_FORWARDING },
+       { _T("Net.Interface.AdminStatus(*)"), H_NetIfInfoFromIOCTL, (TCHAR *)IF_INFO_ADMIN_STATUS, DCI_DT_INT, DCIDESC_NET_INTERFACE_ADMINSTATUS },
+       { _T("Net.Interface.BytesIn(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_BYTES_IN, DCI_DT_UINT,  DCIDESC_NET_INTERFACE_BYTESIN },
+       { _T("Net.Interface.BytesOut(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_BYTES_OUT,     DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESOUT },
+   { _T("Net.Interface.Description(*)"), H_NetIfInfoFromIOCTL, (TCHAR *)IF_INFO_DESCRIPTION, DCI_DT_STRING,    DCIDESC_NET_INTERFACE_DESCRIPTION },
+       { _T("Net.Interface.InErrors(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_ERRORS_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_INERRORS },
+       { _T("Net.Interface.Link(*)"), H_NetIfInfoFromIOCTL, (TCHAR *)IF_INFO_OPER_STATUS, DCI_DT_INT, DCIDESC_NET_INTERFACE_LINK },
+       { _T("Net.Interface.OutErrors(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_ERRORS_OUT, DCI_DT_UINT,      DCIDESC_NET_INTERFACE_OUTERRORS },
+       { _T("Net.Interface.PacketsIn(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_PACKETS_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSIN },
+       { _T("Net.Interface.PacketsOut(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_PACKETS_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSOUT },
+       { _T("Net.IP.Forwarding"), H_NetIpForwarding, (TCHAR *)4, DCI_DT_INT, DCIDESC_NET_IP_FORWARDING },
+       { _T("Net.IP6.Forwarding"), H_NetIpForwarding, (TCHAR *)6, DCI_DT_INT, DCIDESC_NET_IP6_FORWARDING },
+
+#if SIZEOF_LONG > 4
+       { _T("Net.Interface.BytesIn64(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_BYTES_IN_64, DCI_DT_UINT64,  DCIDESC_NET_INTERFACE_BYTESIN },
+       { _T("Net.Interface.BytesOut64(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_BYTES_OUT_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESOUT },
+   { _T("Net.Interface.InErrors64(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_ERRORS_IN_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_INERRORS },
+   { _T("Net.Interface.OutErrors64(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_ERRORS_OUT_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_OUTERRORS },
+   { _T("Net.Interface.PacketsIn64(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_PACKETS_IN_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSIN },
+   { _T("Net.Interface.PacketsOut64(*)"), H_NetIfInfoFromProc, (TCHAR *)IF_INFO_PACKETS_OUT_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSOUT },
+#endif
 
        { _T("PhysicalDisk.SmartAttr(*)"),    H_PhysicalDiskInfo, _T("A"),
                DCI_DT_STRING,  DCIDESC_PHYSICALDISK_SMARTATTR },
index fab6464..e3ed469 100644 (file)
@@ -112,11 +112,17 @@ enum
 #define IF_INFO_BYTES_IN         2
 #define IF_INFO_BYTES_OUT        3
 #define IF_INFO_DESCRIPTION      4
-#define IF_INFO_IN_ERRORS        5
-#define IF_INFO_OUT_ERRORS       6
+#define IF_INFO_ERRORS_IN        5
+#define IF_INFO_ERRORS_OUT       6
 #define IF_INFO_PACKETS_IN       7
 #define IF_INFO_PACKETS_OUT      8
 #define IF_INFO_SPEED            9
+#define IF_INFO_BYTES_IN_64      10
+#define IF_INFO_BYTES_OUT_64     11
+#define IF_INFO_ERRORS_IN_64     12
+#define IF_INFO_ERRORS_OUT_64    13
+#define IF_INFO_PACKETS_IN_64    14
+#define IF_INFO_PACKETS_OUT_64   15
 
 /**
  * Memory stats
index 185e54d..3ab0704 100644 (file)
@@ -651,20 +651,50 @@ LONG H_NetIfInfoFromIOCTL(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValu
    return nRet;
 }
 
+/**
+ * Extract 32 bit value from line
+ */
 static LONG ValueFromLine(char *pszLine, int nPos, TCHAR *pValue)
 {
    int i;
    char *eptr, szBuffer[256];
    const char *pszWord;
-   DWORD dwValue;
    LONG nRet = SYSINFO_RC_ERROR;
 
    for(i = 0, pszWord = pszLine; i <= nPos; i++)
       pszWord = ExtractWordA(pszWord, szBuffer);
-   dwValue = strtoul(szBuffer, &eptr, 0);
+
+   // On 64 bit systems interface counters are 64 bit
+#if SIZEOF_LONG > 4
+   UINT32 value = (UINT32)(strtoull(szBuffer, &eptr, 0) & _ULL(0xFFFFFFFF));
+#else
+   UINT32 value = strtoul(szBuffer, &eptr, 0);
+#endif
    if (*eptr == 0)
    {
-      ret_uint(pValue, dwValue);
+      ret_uint(pValue, value);
+      nRet = SYSINFO_RC_SUCCESS;
+   }
+   return nRet;
+}
+
+/**
+ * Extract 64 bit value from line
+ */
+static LONG ValueFromLine64(char *pszLine, int nPos, TCHAR *pValue)
+{
+   int i;
+   char *eptr, szBuffer[256];
+   const char *pszWord;
+   LONG nRet = SYSINFO_RC_ERROR;
+
+   for(i = 0, pszWord = pszLine; i <= nPos; i++)
+      pszWord = ExtractWordA(pszWord, szBuffer);
+
+   UINT64 value = strtoull(szBuffer, &eptr, 0);
+   if (*eptr == 0)
+   {
+      ret_uint64(pValue, value);
       nRet = SYSINFO_RC_SUCCESS;
    }
    return nRet;
@@ -744,21 +774,39 @@ LONG H_NetIfInfoFromProc(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue
             case IF_INFO_BYTES_IN:
                nRet = ValueFromLine(ptr, 0, pValue);
                break;
+            case IF_INFO_BYTES_IN_64:
+               nRet = ValueFromLine64(ptr, 0, pValue);
+               break;
             case IF_INFO_PACKETS_IN:
                nRet = ValueFromLine(ptr, 1, pValue);
                break;
-            case IF_INFO_IN_ERRORS:
+            case IF_INFO_PACKETS_IN_64:
+               nRet = ValueFromLine64(ptr, 1, pValue);
+               break;
+            case IF_INFO_ERRORS_IN:
                nRet = ValueFromLine(ptr, 2, pValue);
                break;
+            case IF_INFO_ERRORS_IN_64:
+               nRet = ValueFromLine64(ptr, 2, pValue);
+               break;
             case IF_INFO_BYTES_OUT:
                nRet = ValueFromLine(ptr, 8, pValue);
                break;
+            case IF_INFO_BYTES_OUT_64:
+               nRet = ValueFromLine64(ptr, 8, pValue);
+               break;
             case IF_INFO_PACKETS_OUT:
                nRet = ValueFromLine(ptr, 9, pValue);
                break;
-            case IF_INFO_OUT_ERRORS:
+            case IF_INFO_PACKETS_OUT_64:
+               nRet = ValueFromLine64(ptr, 9, pValue);
+               break;
+            case IF_INFO_ERRORS_OUT:
                nRet = ValueFromLine(ptr, 10, pValue);
                break;
+            case IF_INFO_ERRORS_OUT_64:
+               nRet = ValueFromLine64(ptr, 10, pValue);
+               break;
             default:
                nRet = SYSINFO_RC_UNSUPPORTED;
                break;