From d37c4306dfbef35d4ea49a54f702abbdece55b1c Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Mon, 17 Oct 2016 11:10:35 +0200 Subject: [PATCH] ZeroMQ export module, close the context --- conf/glances.conf | 3 ++- glances/exports/glances_zeromq.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index 8e30d07e..663a9a6e 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -322,7 +322,8 @@ db=glances [zeromq] # Configuration for the --export-zeromq option # http://www.zeromq.org -host=127.0.0.1 +# Use * to bind on all interfaces +host=* port=5678 # Glances envelopes the stats in a publish message with two frames: # - First frame containing the following prefix (STRING) diff --git a/glances/exports/glances_zeromq.py b/glances/exports/glances_zeromq.py index 30f18765..5a98179b 100644 --- a/glances/exports/glances_zeromq.py +++ b/glances/exports/glances_zeromq.py @@ -45,6 +45,7 @@ class Export(GlancesExport): sys.exit(2) # Init the ZeroMQ context + self.context = None self.client = self.init() def load_conf(self, section="zeromq"): @@ -74,8 +75,8 @@ class Export(GlancesExport): server_uri = 'tcp://{}:{}'.format(self.host, self.port) try: - context = zmq.Context() - publisher = context.socket(zmq.PUB) + self.context = zmq.Context() + publisher = self.context.socket(zmq.PUB) publisher.bind(server_uri) except Exception as e: logger.critical("Cannot connect to ZeroMQ server %s (%s)" % (server_uri, e)) @@ -86,8 +87,11 @@ class Export(GlancesExport): return publisher def exit(self): - """Close the socket""" - self.client.close() + """Close the socket and context""" + if self.client is not None: + self.client.close() + if self.context is not None: + self.context.destroy() def export(self, name, columns, points): """Write the points to the ZeroMQ server."""