From f0ffd1039214cb70518d61601a7a82e416fba105 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Mon, 8 May 2023 10:41:02 +0200 Subject: [PATCH] Improve Glances start time by disabling Docker and Podman version getter - Related to #1985 --- glances/plugins/containers/glances_docker.py | 25 ++++++++---------- glances/plugins/containers/glances_podman.py | 27 ++++++++------------ 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/glances/plugins/containers/glances_docker.py b/glances/plugins/containers/glances_docker.py index 8ac3fbc958..875952fb52 100644 --- a/glances/plugins/containers/glances_docker.py +++ b/glances/plugins/containers/glances_docker.py @@ -221,6 +221,7 @@ def __init__(self): self.client = None self.ext_name = "containers (Docker)" self.stats_fetchers = {} + self.connect() def connect(self): @@ -233,6 +234,11 @@ def connect(self): logger.error("{} plugin - Can't connect to Docker ({})".format(self.ext_name, e)) self.client = None + def update_version(self): + # Long and not useful anymore because the information is no more displayed in UIs + # return self.client.version() + return {} + def stop(self): # Stop all streaming threads for t in itervalues(self.stats_fetchers): @@ -240,23 +246,12 @@ def stop(self): def update(self, all_tag): """Update Docker stats using the input method.""" - # Docker version - # Example: { - # "KernelVersion": "3.16.4-tinycore64", - # "Arch": "amd64", - # "ApiVersion": "1.15", - # "Version": "1.3.0", - # "GitCommit": "c78088f", - # "Os": "linux", - # "GoVersion": "go1.3.3" - # } - try: - version_stats = self.client.version() - except Exception as e: - # Correct issue#649 - logger.error("{} plugin - Can't get Docker version ({})".format(self.ext_name, e)) + + if not self.client: return {}, [] + version_stats = self.update_version() + # Update current containers list try: # Issue #1152: Docker module doesn't export details about stopped containers diff --git a/glances/plugins/containers/glances_podman.py b/glances/plugins/containers/glances_podman.py index be53acf917..21e66c56e9 100644 --- a/glances/plugins/containers/glances_podman.py +++ b/glances/plugins/containers/glances_podman.py @@ -219,17 +219,12 @@ def __init__(self, podman_sock): if import_podman_error_tag: raise Exception("Missing libs required to run Podman Extension (Containers)") - self.ext_name = "containers (Podman)" - self.client = None + self.ext_name = "containers (Podman)" self.podman_sock = podman_sock self.pods_stats_fetcher = None self.container_stats_fetchers = {} - # Cache version details as the version call is costly (in terms of time) - self._version = {} - self._last_version_update = 0 - self.connect() def connect(self): @@ -238,13 +233,12 @@ def connect(self): self.client = PodmanClient(base_url=self.podman_sock) except Exception as e: logger.error("{} plugin - Can't connect to Podman ({})".format(self.ext_name, e)) + self.client = None def update_version(self): - try: - self._version = self.client.version() - self._last_version_update = time.time() - except Exception as e: - logger.error("{} plugin - Can't get Podman version ({})".format(self.ext_name, e)) + # Long and not useful anymore because the information is no more displayed in UIs + # return self.client.version() + return {} def stop(self): # Stop all streaming threads @@ -257,9 +251,10 @@ def stop(self): def update(self, all_tag): """Update Podman stats using the input method.""" - curr_time = time.time() - if curr_time - self._last_version_update > 300: # 300 seconds - self.update_version() + if not self.client: + return {}, [] + + version_stats = self.update_version() # Update current containers list try: @@ -270,7 +265,7 @@ def update(self, all_tag): self.pods_stats_fetcher = PodmanPodStatsFetcher(self.client.pods) except Exception as e: logger.error("{} plugin - Can't get containers list ({})".format(self.ext_name, e)) - return self._version, [] + return version_stats, [] # Start new thread for new container for container in containers: @@ -298,7 +293,7 @@ def update(self, all_tag): stats["pod_name"] = pod_stats[stats["Id"][:12]]["name"] stats["pod_id"] = pod_stats[stats["Id"][:12]]["pod_id"] - return self._version, container_stats + return version_stats, container_stats @property def key(self):