Skip to content

Commit

Permalink
Update for python3. Need package python3-pika
Browse files Browse the repository at this point in the history
  • Loading branch information
Katyucha committed Apr 7, 2015
1 parent 26bea1a commit 36c2f7d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
21 changes: 21 additions & 0 deletions docs/glances-doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Command-Line Options
export stats to an InfluxDB server
--export-statsd
export stats to a Statsd server
--export-rabbitmq
export stats to a RabbitMQ server
-c CLIENT, --client CLIENT
connect to a Glances server by IPv4/IPv6 address or
hostname
Expand Down Expand Up @@ -824,6 +826,25 @@ Glances will generate stats as:
'glances.load.min1': 0.19,
...
*RabbitMQ*

You can export statistics to an RabbitMQ server (AMQP Broker). The connection should be defined in the Glances configuration file as following:

.. code-block::
[rabbitmq]
host=localhost
port=5672
user=glances
password=glances
queue=glances_queue
and run Glances with:

.. code-block:: console
$ glances --export-rabbitmq
APIs Documentations
===================
Expand Down
10 changes: 7 additions & 3 deletions glances/exports/glances_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

# Import Glances lib
from glances.core.glances_logging import logger
from configparser import NoSectionError, NoOptionError
try:
from configparser import NoOptionError, NoSectionError
except ImportError: # Python 2
from ConfigParser import NoOptionError, NoSectionError
from glances.exports.glances_export import GlancesExport

# Import pika for RabbitMQ
Expand Down Expand Up @@ -78,13 +81,14 @@ def init(self):
"""Init the connection to the rabbitmq server"""
if not self.export_enable:
return None
sparameters = "amqp://"+self.rabbitmq_user+":"+self.rabbitmq_password+"@"+self.rabbitmq_host+":"+self.rabbitmq_port+"/"
try:
parameters = pika.URLParameters("amqp://"+self.rabbitmq_user+":"+self.rabbitmq_password+"@"+self.rabbitmq_host+":"+self.rabbitmq_port+"/")
parameters = pika.URLParameters(sparameters)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
return channel
except Exception as e:
logger.critical("Connection to rabbitMQ failed : %s" % e)
logger.critical("Connection to rabbitMQ failed : %s " % e)
return None

def export(self, name, columns, points):
Expand Down
6 changes: 6 additions & 0 deletions man/glances.1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export stats to an InfluxDB server
.B \-\-export-statsd
export stats to a Statsd server
.TP
.B \-\-export-rabbitmq
export stats to a RabbitMQ server
.TP
.B \-s, \-\-server
run Glances in server mode
.TP
Expand Down Expand Up @@ -234,6 +237,9 @@ Monitor local machine and export stats to a CSV file (standalone mode):
Monitor local machine and export stats to a InfluxDB server with 5s refresh time (standalone mode):
.B $ glances -t 5 --export-influxdb
.PP
Monitor local machine and export stats to a RabbitMQ server with 5s refresh time (standalone mode):
.B $ glances -t 5 --export-rabbitmq
.PP
Start a Glances server (server mode):
.B $ glances -s
.PP
Expand Down

0 comments on commit 36c2f7d

Please sign in to comment.