mirror of
https://github.com/nicolargo/glances.git
synced 2026-03-13 11:28:12 -04:00
ZeroMQ export module, close the context
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user