Compare commits

..

1 Commits

Author SHA1 Message Date
Sylvain Tricot 263a7b2850 Merge tag '0.2' into devel
0.2
2023-02-21 16:08:52 +01:00
1 changed files with 10 additions and 13 deletions

View File

@ -36,19 +36,16 @@ def get_users_list():
def get_resources_percent(username=None):
try:
if username is None:
user_opt = ['-e']
else:
user_opt = ['-u', username]
cmd = Popen(['ps', '-o', 'pcpu', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = list(map(float, cmd.stdout.read().decode('utf8').split()))
cpu_percent = sum(output) / NCPUS
cmd = Popen(['ps', '-o', 'pmem', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = map(float, cmd.stdout.read().decode('utf8').split())
mem_percent = sum(output)
except:
cpu_percent = mem_percent = 0
if username is None:
user_opt = ['-e']
else:
user_opt = ['-u', username]
cmd = Popen(['ps', '-o', 'pcpu', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = list(map(float, cmd.stdout.read().decode('utf8').split()))
cpu_percent = sum(output) / NCPUS
cmd = Popen(['ps', '-o', 'pmem', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = map(float, cmd.stdout.read().decode('utf8').split())
mem_percent = sum(output)
return cpu_percent, mem_percent