summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2024-04-21 18:31:40 +0200
committernicolargo <nicolas@nicolargo.com>2024-04-21 18:31:40 +0200
commit28a3a8874f224d2ecfaa18c17f2ce04bc5124922 (patch)
treef006cd209be55672478e08552df601c45a5c6cac
parent3bc83538b3da1d0713473116106506f7bc98b0dc (diff)
Export individual processes stats - Add some tags for the InfluxDB export #794HEADdevelop
-rw-r--r--conf/glances.conf4
-rw-r--r--glances/__init__.py2
-rw-r--r--glances/exports/glances_influxdb/__init__.py9
-rw-r--r--glances/exports/glances_influxdb2/__init__.py9
4 files changed, 21 insertions, 3 deletions
diff --git a/conf/glances.conf b/conf/glances.conf
index e11d3448..0e7ebbdf 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -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]
diff --git a/glances/__init__.py b/glances/__init__.py
index 23bbd18c..9ac35a19 100644
--- a/glances/__init__.py
+++ b/glances/__init__.py
@@ -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'
diff --git a/glances/exports/glances_influxdb/__init__.py b/glances/exports/glances_influxdb/__init__.py
index a69bfb81..435038f6 100644
--- a/glances/exports/glances_influxdb/__init__.py
+++ b/glances/exports/glances_influxdb/__init__.py
@@ -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
diff --git a/glances/exports/glances_influxdb2/__init__.py b/glances/exports/glances_influxdb2/__init__.py
index 1c33da73..7c0af5a3 100644
--- a/glances/exports/glances_influxdb2/__init__.py
+++ b/glances/exports/glances_influxdb2/__init__.py
@@ -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