mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-28 05:42:57 +03:00
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:
parent
49d15b20da
commit
ac7ab9ea84
@ -22,11 +22,11 @@ try:
|
|||||||
import requests
|
import requests
|
||||||
from dateutil import parser, tz
|
from dateutil import parser, tz
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import_docker_error_tag = True
|
disable_plugin_docker = True
|
||||||
# Display debug message if import KeyError
|
# Display debug message if import KeyError
|
||||||
logger.warning(f"Error loading Docker deps Lib. Docker plugin is disabled ({e})")
|
logger.warning(f"Error loading Docker deps Lib. Docker plugin is disabled ({e})")
|
||||||
else:
|
else:
|
||||||
import_docker_error_tag = False
|
disable_plugin_docker = False
|
||||||
|
|
||||||
|
|
||||||
class DockerStatsFetcher:
|
class DockerStatsFetcher:
|
||||||
@ -213,9 +213,12 @@ class DockerExtension:
|
|||||||
CONTAINER_ACTIVE_STATUS = ['running', 'paused']
|
CONTAINER_ACTIVE_STATUS = ['running', 'paused']
|
||||||
|
|
||||||
def __init__(self):
|
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) ")
|
raise Exception("Missing libs required to run Docker Extension (Containers) ")
|
||||||
|
|
||||||
|
self.display_error = True
|
||||||
|
|
||||||
self.client = None
|
self.client = None
|
||||||
self.ext_name = "containers (Docker)"
|
self.ext_name = "containers (Docker)"
|
||||||
self.stats_fetchers = {}
|
self.stats_fetchers = {}
|
||||||
@ -245,7 +248,7 @@ class DockerExtension:
|
|||||||
def update(self, all_tag) -> Tuple[Dict, List[Dict]]:
|
def update(self, all_tag) -> Tuple[Dict, List[Dict]]:
|
||||||
"""Update Docker stats using the input method."""
|
"""Update Docker stats using the input method."""
|
||||||
|
|
||||||
if not self.client:
|
if not self.client or self.disable:
|
||||||
return {}, []
|
return {}, []
|
||||||
|
|
||||||
version_stats = self.update_version()
|
version_stats = self.update_version()
|
||||||
@ -255,8 +258,13 @@ class DockerExtension:
|
|||||||
# Issue #1152: Docker module doesn't export details about stopped containers
|
# Issue #1152: Docker module doesn't export details about stopped containers
|
||||||
# The Containers/all key of the configuration file should be set to True
|
# The Containers/all key of the configuration file should be set to True
|
||||||
containers = self.client.containers.list(all=all_tag)
|
containers = self.client.containers.list(all=all_tag)
|
||||||
|
self.display_error = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if self.display_error:
|
||||||
logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})")
|
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, []
|
return version_stats, []
|
||||||
|
|
||||||
# Start new thread for new container
|
# Start new thread for new container
|
||||||
|
@ -20,11 +20,11 @@ from glances.stats_streamer import ThreadedIterableStreamer
|
|||||||
try:
|
try:
|
||||||
from podman import PodmanClient
|
from podman import PodmanClient
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import_podman_error_tag = True
|
disable_plugin_podman = True
|
||||||
# Display debug message if import KeyError
|
# Display debug message if import KeyError
|
||||||
logger.warning(f"Error loading Podman deps Lib. Podman feature in the Containers plugin is disabled ({e})")
|
logger.warning(f"Error loading Podman deps Lib. Podman feature in the Containers plugin is disabled ({e})")
|
||||||
else:
|
else:
|
||||||
import_podman_error_tag = False
|
disable_plugin_podman = False
|
||||||
|
|
||||||
|
|
||||||
class PodmanContainerStatsFetcher:
|
class PodmanContainerStatsFetcher:
|
||||||
@ -249,9 +249,12 @@ class PodmanExtension:
|
|||||||
CONTAINER_ACTIVE_STATUS = ['running', 'paused']
|
CONTAINER_ACTIVE_STATUS = ['running', 'paused']
|
||||||
|
|
||||||
def __init__(self, podman_sock):
|
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)")
|
raise Exception("Missing libs required to run Podman Extension (Containers)")
|
||||||
|
|
||||||
|
self.display_error = True
|
||||||
|
|
||||||
self.client = None
|
self.client = None
|
||||||
self.ext_name = "containers (Podman)"
|
self.ext_name = "containers (Podman)"
|
||||||
self.podman_sock = podman_sock
|
self.podman_sock = podman_sock
|
||||||
@ -269,6 +272,7 @@ class PodmanExtension:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"{self.ext_name} plugin - Can't connect to Podman ({e})")
|
logger.debug(f"{self.ext_name} plugin - Can't connect to Podman ({e})")
|
||||||
self.client = None
|
self.client = None
|
||||||
|
self.disable = True
|
||||||
|
|
||||||
def update_version(self):
|
def update_version(self):
|
||||||
# Long and not useful anymore because the information is no more displayed in UIs
|
# 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]]]:
|
def update(self, all_tag) -> Tuple[Dict, list[Dict[str, Any]]]:
|
||||||
"""Update Podman stats using the input method."""
|
"""Update Podman stats using the input method."""
|
||||||
|
|
||||||
if not self.client:
|
if not self.client or self.disable:
|
||||||
return {}, []
|
return {}, []
|
||||||
|
|
||||||
version_stats = self.update_version()
|
version_stats = self.update_version()
|
||||||
@ -298,8 +302,13 @@ class PodmanExtension:
|
|||||||
containers = self.client.containers.list(all=all_tag)
|
containers = self.client.containers.list(all=all_tag)
|
||||||
if not self.pods_stats_fetcher:
|
if not self.pods_stats_fetcher:
|
||||||
self.pods_stats_fetcher = PodmanPodStatsFetcher(self.client.pods)
|
self.pods_stats_fetcher = PodmanPodStatsFetcher(self.client.pods)
|
||||||
|
self.display_error = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if self.display_error:
|
||||||
logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})")
|
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, []
|
return version_stats, []
|
||||||
|
|
||||||
# Start new thread for new container
|
# Start new thread for new container
|
||||||
|
Loading…
Reference in New Issue
Block a user