Refactor init of export modules

pull/1005/head
nicolargo 2017-01-07 16:50:35 +01:00
parent 4223e21c1f
commit 5ce05cef11
10 changed files with 72 additions and 38 deletions

View File

@ -40,13 +40,15 @@ class Export(GlancesExport):
"""Init the Cassandra export IF."""
super(Export, self).__init__(config=config, args=args)
# Load the Cassandra configuration file section
self.host = None
self.port = None
self.protocol_version = 3
# Mandatories configuration keys (additional to host and port)
self.keyspace = None
# Optionals configuration keys
self.protocol_version = 3
self.replication_factor = 2
self.table = None
# Load the Cassandra configuration file section
self.export_enable = self.load_conf('cassandra',
mandatories=['host', 'port', 'keyspace'],
options=['protocol_version',

View File

@ -38,12 +38,14 @@ class Export(GlancesExport):
"""Init the CouchDB export IF."""
super(Export, self).__init__(config=config, args=args)
# Load the Couchdb configuration file section ([export_couchdb])
self.host = None
self.port = None
# Mandatories configuration keys (additional to host and port)
self.db = None
# Optionals configuration keys
self.user = None
self.password = None
self.db = None
# Load the Cassandra configuration file section
self.export_enable = self.load_conf('couchdb',
mandatories=['host', 'port', 'db'],
options=['user', 'password'])

View File

@ -37,10 +37,13 @@ class Export(GlancesExport):
"""Init the ES export IF."""
super(Export, self).__init__(config=config, args=args)
# Load the ES configuration file
self.host = None
self.port = None
# Mandatories configuration keys (additional to host and port)
self.index = None
# Optionals configuration keys
# N/A
# Load the ES configuration file
self.export_enable = self.load_conf('elasticsearch',
mandatories=['host', 'port', 'index'],
options=[])

View File

@ -35,7 +35,7 @@ class GlancesExport(object):
"""Init the export class."""
# Export name (= module name without glances_)
self.export_name = self.__class__.__module__[len('glances_'):]
logger.debug("Init export interface %s" % self.export_name)
logger.debug("Init export module %s" % self.export_name)
# Init the config & args
self.config = config
@ -45,6 +45,10 @@ class GlancesExport(object):
# Had to be set to True in the __init__ class of child
self.export_enable = False
# Mandatory for (most of) the export module
self.host = None
self.port = None
def exit(self):
"""Close the export module."""
logger.debug("Finalise export interface %s" % self.export_name)

View File

@ -43,14 +43,16 @@ class Export(GlancesExport):
"""Init the InfluxDB export IF."""
super(Export, self).__init__(config=config, args=args)
# Load the InfluxDB configuration file
self.host = None
self.port = None
# Mandatories configuration keys (additional to host and port)
self.user = None
self.password = None
self.db = None
# Optionals configuration keys
self.prefix = None
self.tags = None
# Load the InfluxDB configuration file
self.export_enable = self.load_conf('influxdb',
mandatories=['host', 'port',
'user', 'password',

View File

@ -37,11 +37,14 @@ class Export(GlancesExport):
"""Init the OpenTSDB export IF."""
super(Export, self).__init__(config=config, args=args)
# Load the InfluxDB configuration file
self.host = None
self.port = None
# Mandatories configuration keys (additional to host and port)
# N/A
# Optionals configuration keys
self.prefix = None
self.tags = None
# Load the InfluxDB configuration file
self.export_enable = self.load_conf('opentsdb',
mandatories=['host', 'port'],
options=['prefix', 'tags'])

View File

@ -40,13 +40,15 @@ class Export(GlancesExport):
"""Init the RabbitMQ export IF."""
super(Export, self).__init__(config=config, args=args)
# Mandatories configuration keys (additional to host and port)
self.user = None
self.password = None
self.queue = None
# Optionals configuration keys
# N/A
# Load the rabbitMQ configuration file
self.rabbitmq_host = None
self.rabbitmq_port = None
self.rabbitmq_user = None
self.rabbitmq_password = None
self.rabbitmq_queue = None
self.hostname = socket.gethostname()
self.export_enable = self.load_conf('rabbitmq',
mandatories=['host', 'port',
'user', 'password',
@ -55,6 +57,9 @@ class Export(GlancesExport):
if not self.export_enable:
sys.exit(2)
# Get the current hostname
self.hostname = socket.gethostname()
# Init the rabbitmq client
self.client = self.init()
@ -64,10 +69,10 @@ class Export(GlancesExport):
return None
try:
parameters = pika.URLParameters(
'amqp://' + self.rabbitmq_user +
':' + self.rabbitmq_password +
'@' + self.rabbitmq_host +
':' + self.rabbitmq_port + '/')
'amqp://' + self.user +
':' + self.password +
'@' + self.host +
':' + self.port + '/')
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
return channel
@ -86,6 +91,6 @@ class Export(GlancesExport):
data += ", " + columns[i] + "=" + str(points[i])
logger.debug(data)
try:
self.client.basic_publish(exchange='', routing_key=self.rabbitmq_queue, body=data)
self.client.basic_publish(exchange='', routing_key=self.queue, body=data)
except Exception as e:
logger.error("Can not export stats to RabbitMQ (%s)" % e)

View File

@ -39,16 +39,22 @@ class Export(GlancesExport):
"""Init the Riemann export IF."""
super(Export, self).__init__(config=config, args=args)
# Mandatories configuration keys (additional to host and port)
# N/A
# Optionals configuration keys
# N/A
# Load the Riemann configuration
self.riemann_host = None
self.riemann_port = None
self.hostname = socket.gethostname()
self.export_enable = self.load_conf('riemann',
mandatories=['host', 'port'],
options=[])
if not self.export_enable:
sys.exit(2)
# Get the current hostname
self.hostname = socket.gethostname()
# Init the Riemann client
self.client = self.init()
@ -57,7 +63,7 @@ class Export(GlancesExport):
if not self.export_enable:
return None
try:
client = bernhard.Client(host=self.riemann_host, port=self.riemann_port)
client = bernhard.Client(host=self.host, port=self.port)
return client
except Exception as e:
logger.critical("Connection to Riemann failed : %s " % e)

View File

@ -37,10 +37,13 @@ class Export(GlancesExport):
"""Init the Statsd export IF."""
super(Export, self).__init__(config=config, args=args)
# Load the InfluxDB configuration file
self.host = None
self.port = None
# Mandatories configuration keys (additional to host and port)
# N/A
# Optionals configuration keys
self.prefix = None
# Load the InfluxDB configuration file
self.export_enable = self.load_conf('statsd',
mandatories=['host', 'port'],
options=['prefix'])

View File

@ -37,9 +37,13 @@ class Export(GlancesExport):
"""Init the ZeroMQ export IF."""
super(Export, self).__init__(config=config, args=args)
# Mandatories configuration keys (additional to host and port)
self.prefix = None
# Optionals configuration keys
# N/A
# Load the ZeroMQ configuration file section ([export_zeromq])
self.host = None
self.port = None
self.export_enable = self.load_conf('zeromq',
mandatories=['host', 'port', 'prefix'],
options=[])