From 49a579d6d12308c4ba3dd38f0231a0350993dfba Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 12 Apr 2015 21:40:46 +0200 Subject: [PATCH] Correct some PEP on the brand new RabbitMQ export module --- NEWS | 3 ++- conf/glances-test.conf | 7 +++++++ conf/glances.conf | 4 ++-- glances/exports/glances_rabbitmq.py | 6 +++--- setup.py | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 2228d9b4..32e11302 100644 --- a/NEWS +++ b/NEWS @@ -10,7 +10,8 @@ Enhancements and news features: * Grab FAN speed in the Glances sensors plugin (issue #501) * Allow logical mounts points in the FS plugin (issue #448) * Add a --disable-hddtemp to disable HDD temperature module at startup (issue #515) - * Add a quiet mode (-q). Can be usefull if you need a Statsd or Influxdb provider only. + * Add a quiet mode (-q). Can be usefull if you need a Statsd or Influxdb provider only + * Add RabbitMQ export module (issue #540 Thk to @Katyucha) Bugs corrected: diff --git a/conf/glances-test.conf b/conf/glances-test.conf index f68813af..e9369b1c 100644 --- a/conf/glances-test.conf +++ b/conf/glances-test.conf @@ -186,3 +186,10 @@ db=glances host=localhost port=8125 #prefix=glances + +[rabbitmq] +host=localhost +port=5672 +user=guest +password=guest +queue=glances_queue diff --git a/conf/glances.conf b/conf/glances.conf index 8f3ef4ce..69331dde 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -181,6 +181,6 @@ port=8125 [rabbitmq] host=localhost port=5672 -user=glances -password=glances +user=guest +password=guest queue=glances_queue diff --git a/glances/exports/glances_rabbitmq.py b/glances/exports/glances_rabbitmq.py index 2f2c4468..83b7b0be 100644 --- a/glances/exports/glances_rabbitmq.py +++ b/glances/exports/glances_rabbitmq.py @@ -81,7 +81,7 @@ class Export(GlancesExport): """Init the connection to the rabbitmq server""" if not self.export_enable: return None - try: + try: parameters = pika.URLParameters("amqp://"+self.rabbitmq_user+":"+self.rabbitmq_password+"@"+self.rabbitmq_host+":"+self.rabbitmq_port+"/") connection = pika.BlockingConnection(parameters) channel = connection.channel() @@ -97,9 +97,9 @@ class Export(GlancesExport): if not isinstance(points[i], Number): continue else: - data += ", "+columns[i]+"="+str(points[i]) + data += ", " + columns[i] + "=" + str(points[i]) logger.debug(data) try: - self.client.basic_publish(exchange='', routing_key="glances_queue", body=data) + self.client.basic_publish(exchange='', routing_key=self.rabbitmq_queue, body=data) except Exception as e: logger.error("Can not export stats to RabbitMQ (%s)" % e) diff --git a/setup.py b/setup.py index 78192091..72daabda 100755 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ setup( 'BROWSER': ['zeroconf>=0.16', 'netifaces'], 'RAID': ['pymdstat'], 'DOCKER': ['docker-py'], - 'EXPORT': ['influxdb>=1.0.0', 'statsd'], + 'EXPORT': ['influxdb>=1.0.0', 'statsd', 'pika'], 'ACTION': ['pystache'] }, packages=['glances'], -- GitLab