Feature request: Include hostname in all (e.g. kafka) exports #1594

pull/1621/head
nicolargo 2020-02-27 15:17:24 +01:00
parent 1e8bf7bd5f
commit f6533272a5
4 changed files with 20 additions and 4 deletions

View File

@ -488,6 +488,10 @@ host=localhost
port=9092
topic=glances
#compression=gzip
# Tags will be added for all events
#tags=foo:bar,spam:eggs
# You can also use dynamic values
#tags=hostname:`hostname -f`
[zeromq]
# Configuration for the --export zeromq option

View File

@ -16,7 +16,10 @@ following:
user=root
password=root
db=glances
tags=foo:bar,spam:eggs
# Tags will be added for all measurements
#tags=foo:bar,spam:eggs
# You can also use dynamic values
#tags=system:`uname -s`
and run Glances with:

View File

@ -14,6 +14,10 @@ following:
port=9092
topic=glances
#compression=gzip
# Tags will be added for all events
#tags=foo:bar,spam:eggs
# You can also use dynamic values
#tags=hostname:`hostname -f`
Note: you can enable the compression but it consume CPU on your host.
@ -43,4 +47,4 @@ Python code example to consume Kafka Glances plugin:
consumer = KafkaConsumer('glances', value_deserializer=json.loads)
for s in consumer:
print s
print(s)

View File

@ -42,11 +42,14 @@ class Export(GlancesExport):
# Optionals configuration keys
self.compression = None
self.tags = None
# Load the Kafka configuration file section
self.export_enable = self.load_conf('kafka',
mandatories=['host', 'port', 'topic'],
options=['compression'])
mandatories=['host', 'port',
'topic'],
options=['compression',
'tags'])
if not self.export_enable:
sys.exit(2)
@ -79,6 +82,8 @@ class Export(GlancesExport):
# Create DB input
data = dict(zip(columns, points))
if self.tags is not None:
data.update(self.parse_tags(self.tags))
# Send stats to the kafka topic
# key=<plugin name>