new agent metrics Agent.Proxy.ActiveSessions, Agent.Proxy.ConnectionRequests, Agent...
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 29 Aug 2016 19:09:28 +0000 (22:09 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 29 Aug 2016 19:09:28 +0000 (22:09 +0300)
ChangeLog
include/nms_agent.h
src/agent/core/getparam.cpp
src/agent/core/session.cpp

index 44cd2cb..d26d324 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@
 - Built-in superuser account renamed to "system"
 - Default "admin" account now is ordinary member of "Admins" group without built-in privileges
 - New agent metrics for self-monitoring:
+       Agent.Proxy.ActiveSessions, Agent.Proxy.ConnectionRequests, Agent.Proxy.IsEnabled,
        Agent.SNMP.IsProxyEnabled, Agent.SNMP.IsTrapProxyEnabled, Agent.SNMP.Requests,
        Agent.SNMP.Responses, Agent.SNMP.ServerRequests, Agent.SyslogProxy.IsEnabled,
        Agent.SyslogProxy.ReceivedMessages, Agent.SyslogProxy.QueueSize
index 4629a40..dabb17b 100644 (file)
 #define DCIDESC_AGENT_LOCALDB_TOTAL_QUERIES       _T("Agent local database: total queries executed")
 #define DCIDESC_AGENT_LOG_STATUS                  _T("Agent log status")
 #define DCIDESC_AGENT_PROCESSEDREQUESTS           _T("Number of requests processed by agent")
+#define DCIDESC_AGENT_PROXY_ACTIVESESSIONS        _T("Number of active proxy sessions")
+#define DCIDESC_AGENT_PROXY_CONNECTIONREQUESTS    _T("Number of proxy connection requests")
+#define DCIDESC_AGENT_PROXY_ISENABLED             _T("Check if agent proxy is enabled")
 #define DCIDESC_AGENT_REGISTRAR                   _T("Registrar server address set on agent startup")
 #define DCIDESC_AGENT_REJECTEDCONNECTIONS         _T("Number of connections rejected by agent")
 #define DCIDESC_AGENT_SENT_TRAPS                  _T("Number of traps successfully sent to server")
index 076c353..f743fd0 100644 (file)
@@ -27,6 +27,7 @@
  */
 LONG H_ActionList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
 LONG H_ActiveConnections(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
+LONG H_AgentProxyStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
 LONG H_AgentTraps(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
 LONG H_AgentUptime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
 LONG H_CRC32(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
@@ -296,6 +297,9 @@ static NETXMS_SUBAGENT_PARAM m_stdParams[] =
    { _T("Agent.LocalDatabase.TotalQueries"), H_LocalDatabaseCounters, _T("T"), DCI_DT_UINT64, DCIDESC_AGENT_LOCALDB_TOTAL_QUERIES },
    { _T("Agent.LogFile.Status"), H_ComponentStatus, _T("L"), DCI_DT_UINT, DCIDESC_AGENT_LOG_STATUS },
    { _T("Agent.ProcessedRequests"), H_UIntPtr, (TCHAR *)&m_dwProcessedRequests, DCI_DT_UINT, DCIDESC_AGENT_PROCESSEDREQUESTS },
+   { _T("Agent.Proxy.ActiveSessions"), H_AgentProxyStats, _T("A"), DCI_DT_UINT, DCIDESC_AGENT_PROXY_ACTIVESESSIONS },
+   { _T("Agent.Proxy.ConnectionRequests"), H_AgentProxyStats, _T("C"), DCI_DT_UINT64, DCIDESC_AGENT_PROXY_CONNECTIONREQUESTS },
+   { _T("Agent.Proxy.IsEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_PROXY_ISENABLED },
    { _T("Agent.Registrar"), H_StringConstant, g_szRegistrar, DCI_DT_STRING, DCIDESC_AGENT_REGISTRAR },
    { _T("Agent.RejectedConnections"), H_UIntPtr, (TCHAR *)&g_dwRejectedConnections, DCI_DT_UINT, DCIDESC_AGENT_REJECTEDCONNECTIONS },
    { _T("Agent.SentTraps"), H_AgentTraps, _T("S"), DCI_DT_UINT64, DCIDESC_AGENT_SENT_TRAPS },
index 6434edb..d483537 100644 (file)
@@ -46,6 +46,31 @@ void ClearDataCollectionConfiguration();
  */
 ThreadPool *g_snmpProxyThreadPool = NULL;
 
+/**
+ * Agent proxy statistics
+ */
+static UINT64 s_proxyConnectionRequests = 0;
+static VolatileCounter s_activeProxySessions = 0;
+
+/**
+ * Handler for agent proxy stats parameters
+ */
+LONG H_AgentProxyStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session)
+{
+   switch(*arg)
+   {
+      case 'A':
+         ret_uint(value, (UINT32)s_activeProxySessions);
+         break;
+      case 'C':
+         ret_uint64(value, s_proxyConnectionRequests);
+         break;
+      default:
+         return SYSINFO_RC_UNSUPPORTED;
+   }
+   return SYSINFO_RC_SUCCESS;
+}
+
 /**
  * Client communication read thread
  */
@@ -127,6 +152,9 @@ CommSession::CommSession(SOCKET hSocket, const InetAddress &serverAddr, bool mas
  */
 CommSession::~CommSession()
 {
+   if (m_proxyConnection)
+      InterlockedDecrement(&s_activeProxySessions);
+
    shutdown(m_hSocket, SHUT_RDWR);
    closesocket(m_hSocket);
    if (m_hProxySocket != INVALID_SOCKET)
@@ -335,12 +363,14 @@ void CommSession::readThread()
                   delete msg;
                   break;
                case CMD_SETUP_PROXY_CONNECTION:
+                  s_proxyConnectionRequests++;
                   rcc = setupProxyConnection(msg);
                   // When proxy session established incoming messages will
                   // not be processed locally. Acknowledgment message sent
-                  // by SetupProxyConnection() in case of success.
+                  // by setupProxyConnection() in case of success.
                   if (rcc == ERR_SUCCESS)
                   {
+                     InterlockedIncrement(&s_activeProxySessions);
                      m_processingQueue->put(INVALID_POINTER_VALUE);
                   }
                   else