Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from signalfx/add_shutdown_cleanup
Browse files Browse the repository at this point in the history
Add plugin shutdown to cleanup log handler
  • Loading branch information
charless-splunk authored Mar 13, 2017
2 parents 4454b92 + 161cbda commit 2151179
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dockerplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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__)
Expand All @@ -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()
Expand All @@ -647,7 +653,6 @@ def info(self, msg):
def debug(self, msg):
print 'DEBUG: ', msg


collectd = ExecCollectd()
plugin = DockerPlugin()
if len(sys.argv) > 1:
Expand All @@ -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)

0 comments on commit 2151179

Please sign in to comment.