Export individual processes stats - Add some tags for the InfluxDB export #794

This commit is contained in:
nicolargo 2024-04-21 18:31:40 +02:00
parent 3bc83538b3
commit 28a3a8874f
4 changed files with 21 additions and 3 deletions

View File

@ -536,7 +536,7 @@ db=glances
#prefix=foo
# Following tags will be added for all measurements
# You can also use dynamic values.
# Note: hostname is always added as a tag
# Note: hostname and name (for process) are always added as a tag
#tags=foo:bar,spam:eggs,domain:`domainname`
[influxdb2]
@ -559,7 +559,7 @@ token=EjFUTWe8U-MIseEAkaVIgVnej_TrnbdvEcRkaB1imstW7gapSqy6_6-8XD-yd51V0zUUpDy-kA
#prefix=foo
# Following tags will be added for all measurements
# You can also use dynamic values.
# Note: hostname is always added as a tag
# Note: hostname and name (for process) are always added as a tag
#tags=foo:bar,spam:eggs,domain:`domainname`
[cassandra]

View File

@ -20,7 +20,7 @@ import sys
# Global name
# Version should start and end with a numerical char
# See https://packaging.python.org/specifications/core-metadata/#version
__version__ = '4.0.0_beta01'
__version__ = '4.0.0_beta02'
__apiversion__ = '4'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPLv3'

View File

@ -18,6 +18,8 @@ from glances.exports.export import GlancesExport
from influxdb import InfluxDBClient
from influxdb.client import InfluxDBClientError
FIELD_TO_TAG = ['name', 'cmdline']
class Export(GlancesExport):
"""This class manages the InfluxDB export module."""
@ -135,6 +137,13 @@ class Export(GlancesExport):
fields.pop(fields['key'])
# Add the hostname as a tag
tags['hostname'] = self.hostname
# Add name as a tag (example for the process list)
for k in FIELD_TO_TAG:
if k in fields:
tags[k] = str(fields[k])
# Remove it from the field list (can not be a field and a tag)
if k in fields:
fields.pop(fields[k])
# Add the measurement to the list
ret.append({'measurement': name, 'tags': tags, 'fields': fields})
return ret

View File

@ -17,6 +17,8 @@ from glances.exports.export import GlancesExport
from influxdb_client import InfluxDBClient, WriteOptions
FIELD_TO_TAG = ['name', 'cmdline']
class Export(GlancesExport):
"""This class manages the InfluxDB export module."""
@ -146,6 +148,13 @@ class Export(GlancesExport):
fields.pop(fields['key'])
# Add the hostname as a tag
tags['hostname'] = self.hostname
# Add name as a tag (example for the process list)
for k in FIELD_TO_TAG:
if k in fields:
tags[k] = str(fields[k])
# Remove it from the field list (can not be a field and a tag)
if k in fields:
fields.pop(fields[k])
# Add the measurement to the list
ret.append({'measurement': name, 'tags': tags, 'fields': fields})
return ret