It Works ! Have to finalise documentation + configuration file

This commit is contained in:
nicolargo 2024-04-01 19:48:52 +02:00
parent 12d9ac1dff
commit 8107525aef
4 changed files with 19 additions and 20 deletions

View File

@ -360,7 +360,7 @@ nice_warning=-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2
#
# Define the list of processes to export using:
# a comma-separated list of regular expression (apply on name and cmdline)
export=.*firefox.*,.*python.*
export=.*firefox.*
# or an uniq key:value filter
#export=pid:1234

View File

@ -167,12 +167,12 @@ class GlancesExport(object):
i.update(all_limits[plugin])
else:
continue
export_names, export_values = self.__build_export(all_stats[plugin])
export_names, export_values = self.build_export(all_stats[plugin])
self.export(plugin, export_names, export_values)
return True
def __build_export(self, stats):
def build_export(self, stats):
"""Build the export lists."""
export_names = []
export_values = []
@ -194,7 +194,7 @@ class GlancesExport(object):
except IndexError:
value = ''
if isinstance(value, dict):
item_names, item_values = self.__build_export(value)
item_names, item_values = self.build_export(value)
item_names = [pre_key + key.lower() + str(i) for i in item_names]
export_names += item_names
export_values += item_values
@ -205,7 +205,7 @@ class GlancesExport(object):
# Stats is a list (of dict)
# Recursive loop through the list
for item in stats:
item_names, item_values = self.__build_export(item)
item_names, item_values = self.build_export(item)
export_names += item_names
export_values += item_values
return export_names, export_values

View File

@ -70,7 +70,7 @@ class Export(GlancesExport):
def update(self, stats):
"""Update stats in the CSV output file.
This class overwrite the one in the parent class.
Note: This class overwrite the one in the parent class because we need to manage the header.
"""
# Get the stats
all_stats = stats.getAllExportsAsDict(plugin_list=self.plugins_to_export(stats))
@ -82,20 +82,10 @@ class Export(GlancesExport):
# Loop over plugins to export
for plugin in self.plugins_to_export(stats):
if isinstance(all_stats[plugin], list):
for stat in sorted(all_stats[plugin], key=lambda x: x['key']):
# First line: header
if self.first_line:
csv_header += ['{}_{}_{}'.format(plugin, self.get_item_key(stat), item) for item in stat]
# Others lines: stats
csv_data += itervalues(stat)
elif isinstance(all_stats[plugin], dict):
# First line: header
if self.first_line:
fieldnames = iterkeys(all_stats[plugin])
csv_header += ('{}_{}'.format(plugin, fieldname) for fieldname in fieldnames)
# Others lines: stats
csv_data += itervalues(all_stats[plugin])
export_names, export_values = self.build_export(all_stats[plugin])
if self.first_line:
csv_header += export_names
csv_data += export_values
# Export to CSV
# Manage header
@ -119,6 +109,11 @@ class Export(GlancesExport):
self.writer.writerow(csv_data)
self.csv_file.flush()
def export(self, name, columns, points):
"""Export the stats to the CSV file.
For the moment everything is done in the update method."""
pass
def open_csv_file(file_name, file_mode):
return open(file_name, file_mode, newline='')

View File

@ -600,6 +600,10 @@ Examples of use:
args.network_sum = False
args.network_cumul = False
# Processlist id updated in processcount
if getattr(args, 'enable_processlist', False):
enable(args, 'processcount')
def init_client_server(self, args):
"""Init Glances client/server mode."""