1515"""
1616
1717import os
18+ import shlex
1819import sys
1920import subprocess
2021from re import findall , match
@@ -30,6 +31,10 @@ def get_args():
3031 parser .add_argument ("-c" , "--container" , required = True ,
3132 help = "Name of the Container which should be checked" ,
3233 type = str , dest = 'container_name' )
34+ parser .add_argument ("-u" , "--user" , required = False ,
35+ help = "User for rootless containers, default: root" ,
36+ default = 'root' ,
37+ type = str , dest = 'user' )
3338 parser .add_argument ("-t" , "--timeout" , required = False ,
3439 help = "timeout in seconds" , type = int , dest = 'timeout' ,
3540 default = 10 )
@@ -76,9 +81,12 @@ def get_container_pslist(args, docker_env):
7681 """ execute docker ps"""
7782
7883 # Execute "docker ps" command
79- result = subprocess .run (['podman' , 'ps' , '-a' , '-f' , f'name=^{ args .container_name } $' ,
80- '--format' , '"{{.Names}},{{.Status}},{{.Size}},{{.RunningFor}}"' ,
81- '--size' ],
84+ result = subprocess .run (shlex .split ('/usr/bin/systemd-run --machine=%s@'
85+ ' --quiet --user --collect --pipe --wait'
86+ ' podman ps'
87+ ' -a -f name=^%s$'
88+ ' --format "{{.Names}},{{.Status}},{{.Size}},{{.RunningFor}}"'
89+ ' --size' % (args .user , args .container_name )),
8290 shell = False ,
8391 check = False ,
8492 env = docker_env ,
@@ -115,9 +123,13 @@ def get_container_stats(args, docker_env):
115123 """ execute docker stat"""
116124
117125 # Execute "docker stats" command
118- result = subprocess .run (['podman' , 'stats' , args .container_name , '--no-stream' , '--format' ,
119- '"{{.Name}},{{.ID}},{{.CPUPerc}},{{.MemUsage}},\
120- {{.NetIO}},{{.BlockIO}},{{.PIDs}}"' ],
126+ result = subprocess .run (shlex .split ('/usr/bin/systemd-run --machine=%s@'
127+ ' --quiet --user --collect --pipe --wait'
128+ ' podman stats'
129+ ' %s'
130+ ' --no-stream'
131+ ' --format "{{.Name}},{{.ID}},{{.CPUPerc}},{{.MemUsage}},'
132+ '{{.NetIO}},{{.BlockIO}},{{.PIDs}}"' % (args .user , args .container_name )),
121133 shell = False ,
122134 check = False ,
123135 env = docker_env ,
0 commit comments