From 8f6fe14ea11c7970bdd8dfbf0bee97a78ed9fc33 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 4 Nov 2023 11:34:27 +0100 Subject: Corect an issue with default max events number (0 instead of 10) --- conf/glances.conf | 2 +- docker-compose/docker-compose-with-traefik.yml | 19 ++++++++++--------- docker-compose/docker-compose.yml | 19 ++++++++++--------- glances/events.py | 6 ++++-- glances/plugins/alert/__init__.py | 3 ++- glances/plugins/plugin/model.py | 4 ++-- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index d957ed3f..1a59587a 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -428,7 +428,7 @@ disable=False [alert] disable=False # Maximum number of alerts to display (default is 10) -; max_events=10 +;max_events=10 ############################################################################## # Client/server diff --git a/docker-compose/docker-compose-with-traefik.yml b/docker-compose/docker-compose-with-traefik.yml index 32e9ff96..1f98d07b 100644 --- a/docker-compose/docker-compose-with-traefik.yml +++ b/docker-compose/docker-compose-with-traefik.yml @@ -25,15 +25,16 @@ services: - "/run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro" - "./glances.conf:/glances/conf/glances.conf" environment: - - GLANCES_OPT: "-C /glances/conf/glances.conf -w" - - TZ: "${TZ}" - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] + - TZ=${TZ} + - "GLANCES_OPT=-C /glances/conf/glances.conf -w" + # Uncomment for GPU compatibilty (Nvidia) inside the container + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: 1 + # capabilities: [gpu] labels: - "traefik.port=61208" - "traefik.frontend.rule=Host:glances.docker.localhost" diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index d1e18794..84e4bcf7 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -13,12 +13,13 @@ services: - "/run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro" - "./glances.conf:/glances/conf/glances.conf" environment: - - GLANCES_OPT: "-C /glances/conf/glances.conf -w" - - TZ: "${TZ}" - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] \ No newline at end of file + - TZ=${TZ} + - "GLANCES_OPT=-C /glances/conf/glances.conf -w" + # Uncomment for GPU compatibilty (Nvidia) inside the container + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: 1 + # capabilities: [gpu] diff --git a/glances/events.py b/glances/events.py index b1a9ba3b..76ee2fd5 100644 --- a/glances/events.py +++ b/glances/events.py @@ -13,6 +13,7 @@ import time from datetime import datetime from glances.processes import glances_processes, sort_stats +from glances.logger import logger class GlancesEvents(object): @@ -108,7 +109,8 @@ class GlancesEvents(object): self._create_event(event_state, event_type, event_value, proc_list, proc_desc, peak_time) else: # Event exist, update it - self._update_event(event_index, event_state, event_type, event_value, proc_list, proc_desc, peak_time) + self._update_event(event_index, + event_state, event_type, event_value, proc_list, proc_desc, peak_time) return self.len() @@ -128,7 +130,7 @@ class GlancesEvents(object): time.mktime(datetime.now().timetuple()), # START DATE -1, # END DATE event_state, # STATE: WARNING|CRITICAL - event_type, # TYPE: CPU, LOAD, MEM... + event_type, # TYPE: CPU, LOAD, MEM... event_value, # MAX event_value, # AVG event_value, # MIN diff --git a/glances/plugins/alert/__init__.py b/glances/plugins/alert/__init__.py index 950acec5..9cc2fcc0 100644 --- a/glances/plugins/alert/__init__.py +++ b/glances/plugins/alert/__init__.py @@ -183,7 +183,7 @@ class PluginModel(GlancesPluginModel): # Set the maximum number of events to display if config is not None and (config.has_section('alert') or config.has_section('alerts')): - glances_events.set_max_events(config.get_int_value('alert', 'max_events')) + glances_events.set_max_events(config.get_int_value('alert', 'max_events', default=10)) def update(self): """Nothing to do here. Just return the global glances_log.""" @@ -211,6 +211,7 @@ class PluginModel(GlancesPluginModel): # New line ret.append(self.curse_new_line()) # Start + # TODO: Related to #2591, manege TZ in order to make it work inside containers msg = str(datetime.fromtimestamp(alert[0])) ret.append(self.curse_add_line(msg)) # Duration diff --git a/glances/plugins/plugin/model.py b/glances/plugins/plugin/model.py index 671a460f..aa67bcb0 100644 --- a/glances/plugins/plugin/model.py +++ b/glances/plugins/plugin/model.py @@ -73,7 +73,7 @@ class GlancesPluginModel(object): # Internal or external module (former prefixed by 'glances.plugins') _mod = self.__class__.__module__.replace('glances.plugins.', '') self.plugin_name = _mod.split('.')[0] - + if self.plugin_name.startswith('glances_'): self.plugin_name = self.plugin_name.split('glances_')[1] logger.debug("Init {} plugin".format(self.plugin_name)) @@ -689,7 +689,7 @@ class GlancesPluginModel(object): # Add _LOG to the return string # So stats will be highlighted with a specific color log_str = "_LOG" - # Add the log to the list + # Add the log to the events list glances_events.add(ret, stat_name.upper(), value) # Manage threshold -- cgit v1.2.3