summaryrefslogtreecommitdiffstats
path: root/glances/plugins/containers/engines/podman.py
diff options
context:
space:
mode:
Diffstat (limited to 'glances/plugins/containers/engines/podman.py')
-rw-r--r--glances/plugins/containers/engines/podman.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/glances/plugins/containers/engines/podman.py b/glances/plugins/containers/engines/podman.py
index ccf4a566..7324ccd6 100644
--- a/glances/plugins/containers/engines/podman.py
+++ b/glances/plugins/containers/engines/podman.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
@@ -7,9 +6,10 @@
# SPDX-License-Identifier: LGPL-3.0-only
"""Podman Extension unit for Glances' Containers plugin."""
+
from datetime import datetime
-from glances.globals import iterkeys, itervalues, nativestr, pretty_date, string_value_to_float
+from glances.globals import iterkeys, itervalues, nativestr, pretty_date, replace_special_chars, string_value_to_float
from glances.logger import logger
from glances.plugins.containers.stats_streamer import StatsStreamer
@@ -20,7 +20,7 @@ try:
except Exception as e:
import_podman_error_tag = True
# Display debug message if import KeyError
- logger.warning("Error loading Podman deps Lib. Podman feature in the Containers plugin is disabled ({})".format(e))
+ logger.warning(f"Error loading Podman deps Lib. Podman feature in the Containers plugin is disabled ({e})")
else:
import_podman_error_tag = False
@@ -36,7 +36,7 @@ class PodmanContainerStatsFetcher:
self._streamer = StatsStreamer(stats_iterable, initial_stream_value={})
def _log_debug(self, msg, exception=None):
- logger.debug("containers (Podman) ID: {} - {} ({})".format(self._container.id, msg, exception))
+ logger.debug(f"containers (Podman) ID: {self._container.id} - {msg} ({exception})")
logger.debug(self._streamer.stats)
def stop(self):
@@ -95,7 +95,7 @@ class PodmanPodStatsFetcher:
self._streamer = StatsStreamer(stats_iterable, initial_stream_value={}, sleep_duration=2)
def _log_debug(self, msg, exception=None):
- logger.debug("containers (Podman): Pod Manager - {} ({})".format(msg, exception))
+ logger.debug(f"containers (Podman): Pod Manager - {msg} ({exception})")
logger.debug(self._streamer.stats)
def stop(self):
@@ -139,7 +139,7 @@ class PodmanPodStatsFetcher:
def _get_memory_stats(self, stats):
"""Return the container MEMORY.
- Output: a dict {'rss': 1015808, 'cache': 356352, 'usage': ..., 'max_usage': ...}
+ Output: a dict {'usage': ..., 'limit': ...}
"""
if "MemUsage" not in stats or "/" not in stats["MemUsage"]:
self._log_debug("Missing MEM usage fields")
@@ -155,7 +155,7 @@ class PodmanPodStatsFetcher:
self._log_debug("Compute MEM usage failed", e)
return None
- return {"usage": usage, "limit": limit}
+ return {'usage': usage, 'limit': limit, 'inactive_file': 0}
def _get_network_stats(self, stats):
"""Return the container network usage using the Docker API (v1.0 or higher).
@@ -234,7 +234,7 @@ class PodmanContainersExtension:
# PodmanClient works lazily, so make a ping to determine if socket is open
self.client.ping()
except Exception as e:
- logger.error("{} plugin - Can't connect to Podman ({})".format(self.ext_name, e))
+ logger.debug(f"{self.ext_name} plugin - Can't connect to Podman ({e})")
self.client = None
def update_version(self):
@@ -266,7 +266,7 @@ class PodmanContainersExtension:
if not self.pods_stats_fetcher:
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))
+ logger.error(f"{self.ext_name} plugin - Can't get containers list ({e})")
return version_stats, []
# Start new thread for new container
@@ -274,14 +274,14 @@ class PodmanContainersExtension:
if container.id not in self.container_stats_fetchers:
# StatsFetcher did not exist in the internal dict
# Create it, add it to the internal dict
- logger.debug("{} plugin - Create thread for container {}".format(self.ext_name, container.id[:12]))
+ logger.debug(f"{self.ext_name} plugin - Create thread for container {container.id[:12]}")
self.container_stats_fetchers[container.id] = PodmanContainerStatsFetcher(container)
# Stop threads for non-existing containers
- absent_containers = set(iterkeys(self.container_stats_fetchers)) - set(c.id for c in containers)
+ absent_containers = set(iterkeys(self.container_stats_fetchers)) - {c.id for c in containers}
for container_id in absent_containers:
# Stop the StatsFetcher
- logger.debug("{} plugin - Stop thread for old container {}".format(self.ext_name, container_id[:12]))
+ logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
self.container_stats_fetchers[container_id].stop()
# Delete the StatsFetcher from the dict
del self.container_stats_fetchers[container_id]
@@ -334,7 +334,8 @@ class PodmanContainersExtension:
stats['network_rx'] = stats['network'].get('rx') // stats['network'].get('time_since_update')
stats['network_tx'] = stats['network'].get('tx') // stats['network'].get('time_since_update')
stats['uptime'] = pretty_date(started_at)
- stats['command'] = ' '.join(stats['command'])
+ # Manage special chars in command (see isse#2733)
+ stats['command'] = replace_special_chars(' '.join(stats['command']))
else:
stats['io'] = {}
stats['cpu'] = {}