mirror of
https://github.com/nicolargo/glances.git
synced 2026-03-15 20:38:17 -04:00
Merge branch 'develop' of https://github.com/nicolargo/glances into develop
This commit is contained in:
@@ -81,17 +81,24 @@ class GlancesExport(object):
|
||||
else:
|
||||
return ret
|
||||
|
||||
def parse_tags(self):
|
||||
""" Parses some tags into a dict"""
|
||||
if self.tags:
|
||||
def parse_tags(self, tags):
|
||||
"""Parse tags into a dict.
|
||||
|
||||
tags: a comma separated list of 'key:value' pairs.
|
||||
Example: foo:bar,spam:eggs
|
||||
dtags: a dict of tags.
|
||||
Example: {'foo': 'bar', 'spam': 'eggs'}
|
||||
"""
|
||||
dtags = {}
|
||||
if tags:
|
||||
try:
|
||||
self.tags = dict([x.split(':') for x in self.tags.split(',')])
|
||||
dtags = dict([x.split(':') for x in tags.split(',')])
|
||||
except ValueError:
|
||||
# one of the keyvalue pairs was missing
|
||||
logger.info('invalid tags passed: %s', self.tags)
|
||||
self.tags = {}
|
||||
else:
|
||||
self.tags = {}
|
||||
# one of the 'key:value' pairs was missing
|
||||
logger.info('Invalid tags passed: %s', tags)
|
||||
dtags = {}
|
||||
|
||||
return dtags
|
||||
|
||||
def update(self, stats):
|
||||
"""Update stats to a server.
|
||||
|
||||
@@ -51,6 +51,7 @@ class Export(GlancesExport):
|
||||
self.password = None
|
||||
self.db = None
|
||||
self.prefix = None
|
||||
self.tags = None
|
||||
self.export_enable = self.load_conf()
|
||||
if not self.export_enable:
|
||||
sys.exit(2)
|
||||
@@ -87,7 +88,7 @@ class Export(GlancesExport):
|
||||
try:
|
||||
self.tags = self.config.get_value(section, 'tags')
|
||||
except NoOptionError:
|
||||
self.tags = ''
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
@@ -125,9 +126,6 @@ class Export(GlancesExport):
|
||||
logger.critical("InfluxDB database '%s' did not exist. Please create it" % self.db)
|
||||
sys.exit(2)
|
||||
|
||||
# Read tags
|
||||
self.parse_tags()
|
||||
|
||||
return db
|
||||
|
||||
def export(self, name, columns, points):
|
||||
@@ -140,7 +138,7 @@ class Export(GlancesExport):
|
||||
# Create DB input
|
||||
if self.version == INFLUXDB_09:
|
||||
data = [{'measurement': name,
|
||||
'tags': self.tags,
|
||||
'tags': self.parse_tags(self.tags),
|
||||
'fields': dict(zip(columns, points))}]
|
||||
else:
|
||||
data = [{'name': name, 'columns': columns, 'points': [points]}]
|
||||
|
||||
@@ -42,6 +42,7 @@ class Export(GlancesExport):
|
||||
self.host = None
|
||||
self.port = None
|
||||
self.prefix = None
|
||||
self.tags = None
|
||||
self.export_enable = self.load_conf()
|
||||
if not self.export_enable:
|
||||
sys.exit(2)
|
||||
@@ -79,7 +80,7 @@ class Export(GlancesExport):
|
||||
try:
|
||||
self.tags = self.config.get_value(section, 'tags')
|
||||
except NoOptionError:
|
||||
self.tags = ''
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
@@ -96,9 +97,6 @@ class Export(GlancesExport):
|
||||
logger.critical("Cannot connect to OpenTSDB server %s:%s (%s)" % (self.host, self.port, e))
|
||||
sys.exit(2)
|
||||
|
||||
# Read tags
|
||||
self.parse_tags()
|
||||
|
||||
return db
|
||||
|
||||
def export(self, name, columns, points):
|
||||
@@ -108,8 +106,9 @@ class Export(GlancesExport):
|
||||
continue
|
||||
stat_name = '{0}.{1}.{2}'.format(self.prefix, name, columns[i])
|
||||
stat_value = points[i]
|
||||
tags = self.parse_tags(self.tags)
|
||||
try:
|
||||
self.client.send(stat_name, stat_value, **self.tags)
|
||||
self.client.send(stat_name, stat_value, **tags)
|
||||
except Exception as e:
|
||||
logger.error("Can not export stats %s to OpenTSDB (%s)" % (name, e))
|
||||
logger.debug("Export {0} stats to OpenTSDB".format(name))
|
||||
|
||||
Reference in New Issue
Block a user