diff options
author | Nicolas Hennion <nicolashennion@gmail.com> | 2024-10-31 16:28:56 +0000 |
---|---|---|
committer | Nicolas Hennion <nicolashennion@gmail.com> | 2024-10-31 16:28:56 +0000 |
commit | ac7ab9ea842c6a538b630f21789d1e328232f976 (patch) | |
tree | ef7803fb6dca8060a6f993b981f90ca4cbd9b71d | |
parent | 49d15b20dacf6a0fdf5931573f736782234f2a85 (diff) |
Do not display error message in loop when containers list can not be retrieve (only first time after a failure).
-rw-r--r-- | glances/plugins/containers/engines/docker.py | 18 | ||||
-rw-r--r-- | glances/plugins/containers/engines/podman.py | 21 |
2 files changed, 28 insertions, 11 deletions
diff --git a/glances/plugins/containers/engines/docker.py b/glances/plugins/containers/engines/docker.py index 1aa56bf9..55b49d50 100644 --- a/glances/plugins/containers/engines/docker.py +++ b/glances/plugins/containers/engines/docker.py @@ -22,11 +22,11 @@ try: import requests from dateutil import parser, tz except Exception as e: - import_docker_error_tag = True + disable_plugin_docker = True # Display debug message if import KeyError logger.warning(f"Error loading Docker deps Lib. Docker plugin is disabled ({e})") else: - import_docker_error_tag = False + disable_plugin_docker = False class DockerStatsFetcher: @@ -213,9 +213,12 @@ class DockerExtension: CONTAINER_ACTIVE_STATUS = ['running', 'paused'] def __init__(self): - if import_docker_error_tag: + self.disable = disable_plugin_docker + if self.disable: raise Exception("Missing libs required to run Docker Extension (Containers) ") + self.display_error = True + self.client = None self.ext_name = "containers (Docker)" self.stats_fetchers = {} @@ -245,7 +248,7 @@ class DockerExtension: def update(self, all_tag) -> Tuple[Dict, List[Dict]]: """Update Docker stats using the input method.""" - if not self.client: + if not self.client or self.disable: return {}, [] version_stats = self.update_version() @@ -255,8 +258,13 @@ class DockerExtension: # Issue #1152: Docker module doesn't export details about stopped containers # The Containers/all key of the configuration file should be set to True containers = self.client.containers.list(all=all_tag) + self.display_error = True except Exception as e: - logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})") + if self.display_error: + logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})") + self.display_error = False + else: + logger.debug(f"{self.ext_name} plugin - Can't get containers list ({e})") return version_stats, [] # Start new thread for new container diff --git a/glances/plugins/containers/engines/podman.py b/glances/plugins/containers/engines/podman.py index 09c90f95..ed8b5e50 100644 --- a/glances/plugins/containers/engines/podman.py +++ b/glances/plugins/containers/engines/podman.py @@ -20,11 +20,11 @@ from glances.stats_streamer import ThreadedIterableStreamer try: from podman import PodmanClient except Exception as e: - import_podman_error_tag = True + disable_plugin_podman = True # Display debug message if import KeyError logger.warning(f"Error loading Podman deps Lib. Podman feature in the Containers plugin is disabled ({e})") else: - import_podman_error_tag = False + disable_plugin_podman = False class PodmanContainerStatsFetcher: @@ -249,9 +249,12 @@ class PodmanExtension: CONTAINER_ACTIVE_STATUS = ['running', 'paused'] def __init__(self, podman_sock): - if import_podman_error_tag: + self.disable = disable_plugin_podman + if self.disable: raise Exception("Missing libs required to run Podman Extension (Containers)") + self.display_error = True + self.client = None self.ext_name = "containers (Podman)" self.podman_sock = podman_sock @@ -261,7 +264,7 @@ class PodmanExtension: self.connect() def connect(self): - """Connect to Podman.""" + """Connect to Podman.""" try: self.client = PodmanClient(base_url=self.podman_sock) # PodmanClient works lazily, so make a ping to determine if socket is open @@ -269,6 +272,7 @@ class PodmanExtension: except Exception as e: logger.debug(f"{self.ext_name} plugin - Can't connect to Podman ({e})") self.client = None + self.disable = True def update_version(self): # Long and not useful anymore because the information is no more displayed in UIs @@ -286,7 +290,7 @@ class PodmanExtension: def update(self, all_tag) -> Tuple[Dict, list[Dict[str, Any]]]: """Update Podman stats using the input method.""" - if not self.client: + if not self.client or self.disable: return {}, [] version_stats = self.update_version() @@ -298,8 +302,13 @@ class PodmanExtension: containers = self.client.containers.list(all=all_tag) if not self.pods_stats_fetcher: self.pods_stats_fetcher = PodmanPodStatsFetcher(self.client.pods) + self.display_error = True except Exception as e: - logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})") + if self.display_error: + logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})") + self.display_error = False + else: + logger.debug(f"{self.ext_name} plugin - Can't get containers list ({e})") return version_stats, [] # Start new thread for new container |