Compare commits

..

4 Commits
0.1 ... master

Author SHA1 Message Date
Sylvain Tricot 1071f4b66e Deal with deleted users before logind restart 2024-04-03 22:11:37 +02:00
Sylvain Tricot 007b0efb5d Merge branch 'release/0.2' 2023-02-21 16:08:45 +01:00
Sylvain Tricot a431e7af1d Change shebang
The default python is not python3 in debian...
This commit changes explicitely the shebang line
2023-02-21 16:06:54 +01:00
Sylvain Tricot 41e3f4735b Merge tag '0.1' into devel
0.1
2023-02-21 15:57:50 +01:00
1 changed files with 14 additions and 11 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# coding: utf-8 # coding: utf-8
# #
# Copyright © 2023 - Rennes Physics Institute # Copyright © 2023 - Rennes Physics Institute
@ -36,16 +36,19 @@ def get_users_list():
def get_resources_percent(username=None): def get_resources_percent(username=None):
if username is None: try:
user_opt = ['-e'] if username is None:
else: user_opt = ['-e']
user_opt = ['-u', username] else:
cmd = Popen(['ps', '-o', 'pcpu', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT) user_opt = ['-u', username]
output = list(map(float, cmd.stdout.read().decode('utf8').split())) cmd = Popen(['ps', '-o', 'pcpu', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
cpu_percent = sum(output) / NCPUS output = list(map(float, cmd.stdout.read().decode('utf8').split()))
cmd = Popen(['ps', '-o', 'pmem', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT) cpu_percent = sum(output) / NCPUS
output = map(float, cmd.stdout.read().decode('utf8').split()) cmd = Popen(['ps', '-o', 'pmem', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
mem_percent = sum(output) output = map(float, cmd.stdout.read().decode('utf8').split())
mem_percent = sum(output)
except:
cpu_percent = mem_percent = 0
return cpu_percent, mem_percent return cpu_percent, mem_percent