Do not display error message in loop when containers list can not be retrieve (only first time after a failure).

This commit is contained in:
Nicolas Hennion 2024-10-31 16:28:56 +00:00
parent 49d15b20da
commit ac7ab9ea84
2 changed files with 28 additions and 11 deletions

View File

@ -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:
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

View File

@ -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
@ -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:
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