From 161cbda4c38279d7483e7fd24bacc77aca446ebc Mon Sep 17 00:00:00 2001 From: Drew Griffin Date: Mon, 13 Mar 2017 10:18:56 -0400 Subject: [PATCH] Add plugin shutdown to cleanup log handler --- dockerplugin.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dockerplugin.py b/dockerplugin.py index c0b9b56..beb1b34 100755 --- a/dockerplugin.py +++ b/dockerplugin.py @@ -463,7 +463,8 @@ def init_callback(self): .format(url=self.docker_url)) return False - collectd.register_read(self.read_callback, interval=COLLECTION_INTERVAL) + collectd.register_read(self.read_callback, + interval=COLLECTION_INTERVAL) log.notice(('Collecting stats about Docker containers from {url} ' '(API version {version}; timeout: {timeout}s).') .format(url=self.docker_url, @@ -601,6 +602,12 @@ def notice(self, msg): self.log(25, msg) +def shutdown(): + """Cleanup on plugin shutdown.""" + log.info("dockerplugin shutting down") + log.removeHandler(handle) + + # Set up logging logging.setLoggerClass(CollectdLogger) log = logging.getLogger(__name__) @@ -624,7 +631,6 @@ def dispatch(self): print 'PUTVAL', identifier, \ ':'.join(map(str, [int(self.time)] + self.values)) - class ExecCollectd: def Values(self): return ExecCollectdValues() @@ -647,7 +653,6 @@ def info(self, msg): def debug(self, msg): print 'DEBUG: ', msg - collectd = ExecCollectd() plugin = DockerPlugin() if len(sys.argv) > 1: @@ -668,3 +673,4 @@ def debug(self, msg): plugin = DockerPlugin() collectd.register_config(plugin.configure_callback) collectd.register_init(plugin.init_callback) + collectd.register_shutdown(shutdown)