Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
1071f4b66e | |
|
|
007b0efb5d | |
|
|
a431e7af1d | |
|
|
41e3f4735b |
25
lsusers.py
25
lsusers.py
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
#
|
||||
# Copyright © 2023 - Rennes Physics Institute
|
||||
|
|
@ -36,16 +36,19 @@ def get_users_list():
|
|||
|
||||
|
||||
def get_resources_percent(username=None):
|
||||
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)
|
||||
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
|
||||
return cpu_percent, mem_percent
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue