From a8053862550058fde46fe1a0a40b6596cca9109b Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 22 Jan 2023 09:54:56 +0100 Subject: [PATCH] Add Podman IO, but not workking for the moment because https://github.com/containers/podman/issues/11695 --- glances/compat.py | 6 +++++- glances/plugins/glances_docker.py | 11 ++++++----- unitest.py | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/glances/compat.py b/glances/compat.py index 95955794d9..ac7c624048 100644 --- a/glances/compat.py +++ b/glances/compat.py @@ -377,7 +377,7 @@ def string_value_to_float(s): 'TB': 1000000000000, 'PB': 1000000000000000, } - unpack_string = [float(i[0]) if i[1] == '' else i[1].upper() for i in re.findall(r'([\d.]+)|([^\d.]+)', s.replace(' ', ''))] + unpack_string = [i[0] if i[1] == '' else i[1].upper() for i in re.findall(r'([\d.]+)|([^\d.]+)', s.replace(' ', ''))] if len(unpack_string) == 2: value, unit = unpack_string elif len(unpack_string) == 1: @@ -385,4 +385,8 @@ def string_value_to_float(s): unit = None else: return None + try: + value = float(unpack_string[0]) + except ValueError: + return None return value * convert_dict[unit] diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index f2a281b919..1eeb04ac30 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -454,13 +454,14 @@ def update_podman(self): 'limit': string_value_to_float(podman_stats[container_stats['IdShort']]['MemUsage'].split(' / ')[1]), } container_stats['memory_percent'] = float(podman_stats[container_stats['IdShort']]['Mem'][:-1]) - # Is it possible ? + # Not available for the moment: https://github.com/containers/podman/issues/11695 container_stats['io'] = {} - container_stats['io_r'] = None - container_stats['io_w'] = None + container_stats['io_r'] = string_value_to_float(podman_stats[container_stats['IdShort']]['BlockIO'].split(' / ')[0]) + container_stats['io_w'] = string_value_to_float(podman_stats[container_stats['IdShort']]['BlockIO'].split(' / ')[1]) container_stats['network'] = {} - container_stats['network_rx'] = None - container_stats['network_tx'] = None + container_stats['network_rx'] = string_value_to_float(podman_stats[container_stats['IdShort']]['NetIO'].split(' / ')[0]) + container_stats['network_tx'] = string_value_to_float(podman_stats[container_stats['IdShort']]['NetIO'].split(' / ')[1]) + # container_stats['Uptime'] = None else: container_stats['cpu'] = {} diff --git a/unitest.py b/unitest.py index 25193d9ad1..ca9703a924 100755 --- a/unitest.py +++ b/unitest.py @@ -296,6 +296,7 @@ def test_018_string_value_to_float(self): self.assertEqual(string_value_to_float('15.5MB'), 15500000.0) self.assertEqual(string_value_to_float('25.9'), 25.9) self.assertEqual(string_value_to_float('12'), 12) + self.assertEqual(string_value_to_float('--'), None) def test_094_thresholds(self): """Test thresholds classes"""