Skip to content

Commit

Permalink
Improve Glances start time by disabling Docker and Podman version get…
Browse files Browse the repository at this point in the history
…ter - Related to #1985
  • Loading branch information
nicolargo committed May 8, 2023
1 parent 985dd6c commit f0ffd10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
25 changes: 10 additions & 15 deletions glances/plugins/containers/glances_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def __init__(self):
self.client = None
self.ext_name = "containers (Docker)"
self.stats_fetchers = {}

self.connect()

def connect(self):
Expand All @@ -233,30 +234,24 @@ 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):
t.stop()

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
Expand Down
27 changes: 11 additions & 16 deletions glances/plugins/containers/glances_podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f0ffd10

Please sign in to comment.