bundles/sshmon: fix occasional KeyErrors in check_cpu_stats
All checks were successful
bundlewrap/pipeline/head This commit looks good
All checks were successful
bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
94dba9139b
commit
455d4d7551
1 changed files with 10 additions and 1 deletions
|
@ -5,7 +5,16 @@ from subprocess import check_output
|
|||
from sys import exit
|
||||
|
||||
try:
|
||||
top_output = check_output("top -b -n1 -d1 | grep -i '^\%cpu'", shell=True).decode('UTF-8').split(': ', 2)[1].strip()
|
||||
top_output = None
|
||||
|
||||
for line in check_output(['top', '-b', '-n1', '-d1']).decode('UTF-8').splitlines():
|
||||
if line.lower().strip().startswith('%cpu'):
|
||||
top_output = line.lower().split(':', 2)[1]
|
||||
break
|
||||
|
||||
if not top_output:
|
||||
print('%cpu not found in top output')
|
||||
exit(3)
|
||||
|
||||
cpu_usage = {}
|
||||
for value, identifier in findall('([0-9\.\,]{3,5}) ([a-z]{2})', top_output):
|
||||
|
|
Loading…
Reference in a new issue