Skip to content

Commit

Permalink
Merge pull request #2374 from nicolargo/issue1985
Browse files Browse the repository at this point in the history
Podman support for glances
  • Loading branch information
nicolargo committed May 8, 2023
2 parents 9657fcb + a29f335 commit 2a1b1db
Show file tree
Hide file tree
Showing 12 changed files with 1,251 additions and 777 deletions.
4 changes: 3 additions & 1 deletion conf/glances.conf
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ port_default_gateway=True
#web_4_url=https://blog.nicolargo.com/nonexist
#web_4_description=Intranet

[docker]
[containers]
disable=False
# Only show specific containers (comma separated list of container name or regular expression)
# Comment this line to display all containers (default configuration)
Expand All @@ -417,6 +417,8 @@ max_name_size=20
# By default, Glances only display running containers
# Set the following key to True to display all containers
all=False
# Define Podman sock
#podman_sock=unix:///run/user/1000/podman/podman.sock

[amps]
# AMPs configuration are defined in the bottom of this file
Expand Down
37 changes: 37 additions & 0 deletions glances/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import subprocess
import os
from datetime import datetime
import re

from glances.logger import logger

Expand Down Expand Up @@ -366,3 +367,39 @@ def urlopen_auth(url, username, password):
headers={'Authorization': 'Basic ' + base64.b64encode(('%s:%s' % (username, password)).encode()).decode()},
)
)


def string_value_to_float(s):
"""Convert a string with a value and an unit to a float.
Example:
'12.5 MB' -> 12500000.0
'32.5 GB' -> 32500000000.0
Args:
s (string): Input string with value and unit
Output:
float: The value in float
"""
convert_dict = {
None: 1,
'B': 1,
'KB': 1000,
'MB': 1000000,
'GB': 1000000000,
'TB': 1000000000000,
'PB': 1000000000000000,
}
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:
value = unpack_string[0]
unit = None
else:
return None
try:
value = float(unpack_string[0])
except ValueError:
return None
return value * convert_dict[unit]
6 changes: 3 additions & 3 deletions glances/outputs/glances_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _GlancesCurses(object):
'c': {'sort_key': 'cpu_percent'},
'C': {'switch': 'disable_cloud'},
'd': {'switch': 'disable_diskio'},
'D': {'switch': 'disable_docker'},
'D': {'switch': 'disable_containers'},
# 'e' > Enable/Disable process extended
# 'E' > Erase the process filter
# 'f' > Show/hide fs / folder stats
Expand Down Expand Up @@ -124,7 +124,7 @@ class _GlancesCurses(object):
_left_sidebar_max_width = 34

# Define right sidebar
_right_sidebar = ['docker', 'processcount', 'amps', 'processlist', 'alert']
_right_sidebar = ['containers', 'processcount', 'amps', 'processlist', 'alert']

def __init__(self, config=None, args=None):
# Init
Expand Down Expand Up @@ -617,7 +617,7 @@ def display(self, stats, cs_status=None):
max_processes_displayed = (
self.term_window.getmaxyx()[0]
- 11
- (0 if 'docker' not in __stat_display else self.get_stats_display_height(__stat_display["docker"]))
- (0 if 'containers' not in __stat_display else self.get_stats_display_height(__stat_display["containers"]))
- (
0
if 'processcount' not in __stat_display
Expand Down
Empty file.
Loading

0 comments on commit 2a1b1db

Please sign in to comment.