Reduce logging on AgentX connections
Previous logging was very noisy when the agent connection to snmpd drops: [ERROR ] agentx.network - run : Empty PDU, connection closed! [INFO ] agentx.network - disconnect : Disconnecting from localhost:705 [ERROR ] agentx.agent - run : An exception occurred: Empty PDU, disconnecting [ERROR ] agentx.agent - run : Reconnecting [INFO ] agentx.agent - run : Opening AgentX connection [INFO ] agentx.network - connect : Connecting to localhost:705 [ERROR ] agentx.network - connect : Failed to connect to localhost:705 [ERROR ] agentx.agent - run : An exception occurred: Not connected [ERROR ] agentx.agent - run : Reconnecting [INFO ] agentx.agent - run : Opening AgentX connection [INFO ] agentx.network - connect : Connecting to localhost:705 [ERROR ] agentx.network - connect : Failed to connect to localhost:705 [ERROR ] agentx.agent - run : An exception occurred: Not connected [ERROR ] agentx.agent - run : Reconnecting Also, reconnects were attempted every 0.1s, but field research shows that snmpd, if it restarts, takes ~3-5 seconds to come back (note: this is also due to a systemd delay in restarting it upon failures). Hammering the connection is not useful. This change refactors the logging, to avoid redundant messages: - sleep 1s between attempts (reducing the loop by 10x) - Either print 'Connected to' or 'Failed to connect to', not both. - Remove the 'reconnecting' superfluous message
This commit is contained in:
@ -71,10 +71,9 @@ class Agent(object):
|
||||
try:
|
||||
self._net.run()
|
||||
except Exception as e:
|
||||
self.logger.error("An exception occurred: %s" % e)
|
||||
self.logger.error("Reconnecting")
|
||||
self.logger.error("Disconnecting due to exception: %s" % e)
|
||||
self._net.disconnect()
|
||||
time.sleep(0.1)
|
||||
time.sleep(1)
|
||||
|
||||
def stop(self):
|
||||
self.logger.debug("Stopping")
|
||||
|
Reference in New Issue
Block a user