From 786773f7c5e928380378992129f7454b44e92f1b Mon Sep 17 00:00:00 2001 From: Victor Kirhenshtein Date: Mon, 29 Aug 2016 13:07:18 +0300 Subject: [PATCH] additional agent metrics for self-monitoring (SNMP proxy and syslog proxy stats) --- ChangeLog | 4 ++++ include/nms_agent.h | 9 +++++++-- src/agent/core/getparam.cpp | 35 ++++++++++++++++++++++++++--------- src/agent/core/snmpproxy.cpp | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index d0c8ba7b7..6ed54a1db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,10 @@ - Syslog proxy in agent - 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.SNMP.IsProxyEnabled, Agent.SNMP.IsTrapProxyEnabled, Agent.SNMP.Requests, + Agent.SNMP.Responses, Agent.SNMP.ServerRequests, Agent.SyslogProxy.IsEnabled, + Agent.SyslogProxy.ReceivedMessages, Agent.SyslogProxy.QueueSize - Management console - New editors for Agent Config Policy and Log Parser Policy. - DCI summary tables with empty menu path not shown in object context menu diff --git a/include/nms_agent.h b/include/nms_agent.h index 0fca91ab2..4629a40eb 100644 --- a/include/nms_agent.h +++ b/include/nms_agent.h @@ -260,12 +260,17 @@ #define DCIDESC_AGENT_LOG_STATUS _T("Agent log status") #define DCIDESC_AGENT_PROCESSEDREQUESTS _T("Number of requests processed by agent") #define DCIDESC_AGENT_REGISTRAR _T("Registrar server address set on agent startup") -#define DCIDESC_AGENT_RECEIVEDSYSLOGMESSAGES _T("Number of syslog messages received by agent") #define DCIDESC_AGENT_REJECTEDCONNECTIONS _T("Number of connections rejected by agent") #define DCIDESC_AGENT_SENT_TRAPS _T("Number of traps successfully sent to server") +#define DCIDESC_AGENT_SNMP_ISPROXYENABLED _T("Check if SNMP proxy is enabled") +#define DCIDESC_AGENT_SNMP_REQUESTS _T("Number of SNMP requests sent") +#define DCIDESC_AGENT_SNMP_RESPONSES _T("Number of SNMP responses received") +#define DCIDESC_AGENT_SNMP_SERVERREQUESTS _T("Number of SNMP proxy requests received from server") #define DCIDESC_AGENT_SOURCEPACKAGESUPPORT _T("Check if source packages are supported") #define DCIDESC_AGENT_SUPPORTEDCIPHERS _T("List of ciphers supported by agent") -#define DCIDESC_AGENT_SYSLOGPROXYQUEUESIZE _T("Agent syslog proxy queue size") +#define DCIDESC_AGENT_SYSLOGPROXY_ISENABLED _T("Check if syslog proxy is enabled") +#define DCIDESC_AGENT_SYSLOGPROXY_RECEIVEDMSGS _T("Number of syslog messages received by agent") +#define DCIDESC_AGENT_SYSLOGPROXY_QUEUESIZE _T("Agent syslog proxy queue size") #define DCIDESC_AGENT_THREADPOOL_ACTIVEREQUESTS _T("Agent thread pool {instance}: active requests") #define DCIDESC_AGENT_THREADPOOL_CURRSIZE _T("Agent thread pool {instance}: current size") #define DCIDESC_AGENT_THREADPOOL_LOAD _T("Agent thread pool {instance}: current load") diff --git a/src/agent/core/getparam.cpp b/src/agent/core/getparam.cpp index d2c002f89..076c35352 100644 --- a/src/agent/core/getparam.cpp +++ b/src/agent/core/getparam.cpp @@ -25,29 +25,30 @@ /** * Parameter handlers */ +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_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); LONG H_DataCollectorQueueSize(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); LONG H_DirInfo(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_ExternalParameter(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_ExternalList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session); LONG H_FileTime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); LONG H_IsSubagentLoaded(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); LONG H_MD5Hash(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_PlatformName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_ResolverAddrByName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_ResolverNameByAddr(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_SessionAgents(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session); LONG H_SHA1Hash(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); +LONG H_SNMPProxyStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); LONG H_SubAgentList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session); LONG H_SubAgentTable(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session); LONG H_SyslogStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); -LONG H_ActionList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session); -LONG H_ExternalParameter(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); -LONG H_ExternalList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session); -LONG H_PlatformName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); -LONG H_SessionAgents(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session); LONG H_SystemTime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); LONG H_ThreadPoolInfo(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); LONG H_ThreadPoolList(const TCHAR *param, const TCHAR *arg, StringList *value, AbstractCommSession *session); -LONG H_ResolverAddrByName(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); -LONG H_ResolverNameByAddr(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); #ifdef _WIN32 LONG H_CPUCount(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session); @@ -229,6 +230,16 @@ static LONG H_LocalDatabaseCounters(const TCHAR *pszParam, const TCHAR *pArg, TC return SYSINFO_RC_SUCCESS; } +/** + * Handler for flag query parameters + */ +static LONG H_FlagValue(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session) +{ + UINT32 flag = CAST_FROM_POINTER(arg, UINT32); + ret_int(value, (g_dwFlags & flag) ? 1 : 0); + return SYSINFO_RC_SUCCESS; +} + /** * Standard agent's parameters */ @@ -286,12 +297,18 @@ static NETXMS_SUBAGENT_PARAM m_stdParams[] = { _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.Registrar"), H_StringConstant, g_szRegistrar, DCI_DT_STRING, DCIDESC_AGENT_REGISTRAR }, - { _T("Agent.ReceivedSyslogMessages"), H_SyslogStats, _T("R"), DCI_DT_UINT64, DCIDESC_AGENT_RECEIVEDSYSLOGMESSAGES }, { _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 }, + { _T("Agent.SNMP.IsProxyEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_SNMP_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_SNMP_ISPROXYENABLED }, + { _T("Agent.SNMP.IsTrapProxyEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_SNMP_TRAP_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_SNMP_ISPROXYENABLED }, + { _T("Agent.SNMP.Requests"), H_SNMPProxyStats, _T("R"), DCI_DT_UINT64, DCIDESC_AGENT_SNMP_REQUESTS }, + { _T("Agent.SNMP.Responses"), H_SNMPProxyStats, _T("r"), DCI_DT_UINT64, DCIDESC_AGENT_SNMP_RESPONSES }, + { _T("Agent.SNMP.ServerRequests"), H_SNMPProxyStats, _T("S"), DCI_DT_UINT64, DCIDESC_AGENT_SNMP_SERVERREQUESTS }, { _T("Agent.SourcePackageSupport"), H_StringConstant, _T("0"), DCI_DT_INT, DCIDESC_AGENT_SOURCEPACKAGESUPPORT }, { _T("Agent.SupportedCiphers"), H_SupportedCiphers, NULL, DCI_DT_STRING, DCIDESC_AGENT_SUPPORTEDCIPHERS }, - { _T("Agent.SyslogProxyQueueSize"), H_SyslogStats, _T("Q"), DCI_DT_UINT, DCIDESC_AGENT_SYSLOGPROXYQUEUESIZE }, + { _T("Agent.SyslogProxy.IsEnabled"), H_FlagValue, CAST_TO_POINTER(AF_ENABLE_SYSLOG_PROXY, TCHAR *), DCI_DT_UINT, DCIDESC_AGENT_SYSLOGPROXY_ISENABLED }, + { _T("Agent.SyslogProxy.ReceivedMessages"), H_SyslogStats, _T("R"), DCI_DT_UINT64, DCIDESC_AGENT_SYSLOGPROXY_RECEIVEDMSGS }, + { _T("Agent.SyslogProxy.QueueSize"), H_SyslogStats, _T("Q"), DCI_DT_UINT, DCIDESC_AGENT_SYSLOGPROXY_QUEUESIZE }, { _T("Agent.ThreadPool.ActiveRequests(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_REQUESTS, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_ACTIVEREQUESTS }, { _T("Agent.ThreadPool.CurrSize(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_CURR_SIZE, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_CURRSIZE }, { _T("Agent.ThreadPool.Load(*)"), H_ThreadPoolInfo, (TCHAR *)THREAD_POOL_LOAD, DCI_DT_UINT, DCIDESC_AGENT_THREADPOOL_LOAD }, diff --git a/src/agent/core/snmpproxy.cpp b/src/agent/core/snmpproxy.cpp index 62ddb1683..0c88cce46 100644 --- a/src/agent/core/snmpproxy.cpp +++ b/src/agent/core/snmpproxy.cpp @@ -27,6 +27,35 @@ */ #define SNMP_BUFFER_SIZE 65536 +/** + * SNMP proxy stats + */ +static UINT64 s_serverRequests = 0; +static UINT64 s_snmpRequests = 0; +static UINT64 s_snmpResponses = 0; + +/** + * Handler for SNMP proxy information parameters + */ +LONG H_SNMPProxyStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session) +{ + switch(*arg) + { + case 'R': // SNMP requests + ret_uint64(value, s_snmpRequests); + break; + case 'r': // SNMP responses + ret_uint64(value, s_snmpResponses); + break; + case 'S': // server requests + ret_uint64(value, s_serverRequests); + break; + default: + return SYSINFO_RC_UNSUPPORTED; + } + return SYSINFO_RC_SUCCESS; +} + /** * Read PDU from network */ @@ -88,6 +117,7 @@ void CommSession::proxySnmpRequest(NXCPMessage *request) response.setCode(CMD_REQUEST_COMPLETED); response.setId(request->getId()); + s_serverRequests++; UINT32 dwSizeIn = request->getFieldAsUInt32(VID_PDU_SIZE); if (dwSizeIn > 0) { @@ -112,9 +142,11 @@ void CommSession::proxySnmpRequest(NXCPMessage *request) { if (send(hSocket, (char *)pduIn, dwSizeIn, 0) == (int)dwSizeIn) { + s_snmpRequests++; UINT32 dwSizeOut; if (ReadPDU(hSocket, pduOut, &dwSizeOut)) { + s_snmpResponses++; response.setField(VID_PDU_SIZE, dwSizeOut); response.setField(VID_PDU, pduOut, dwSizeOut); break; -- 2.20.1