fix: filter measurement artifacts from processes endpoint, sort by memory
This commit is contained in:
parent
4a271496c3
commit
b206b4e995
1 changed files with 6 additions and 3 deletions
|
|
@ -200,16 +200,19 @@ def server_stats():
|
|||
@app.route('/api/processes')
|
||||
def top_processes():
|
||||
try:
|
||||
raw = shell("ps aux --sort=-%cpu | awk 'NR>1 && NR<=8{print $2,$3,$4,$11}' | head -7")
|
||||
raw = shell("ps aux --sort=-%mem | awk 'NR>1{print $2,$3,$4,$11}' | grep -v -E '(ps aux|awk |grep |sshd:|bash -c)' | head -7")
|
||||
procs = []
|
||||
for line in raw.strip().split('\n'):
|
||||
parts = line.split(None, 3)
|
||||
if len(parts) >= 4:
|
||||
name = parts[3].split('/')[-1][:20]
|
||||
if name in ('ps', 'awk', 'head', 'grep', 'sh', 'bash'):
|
||||
continue
|
||||
procs.append({
|
||||
'pid': parts[0],
|
||||
'cpu': float(parts[1]),
|
||||
'mem': float(parts[2]),
|
||||
'name': parts[3].split('/')[-1][:20]
|
||||
'name': name
|
||||
})
|
||||
elif len(parts) == 3:
|
||||
procs.append({
|
||||
|
|
@ -218,7 +221,7 @@ def top_processes():
|
|||
'mem': float(parts[2]),
|
||||
'name': 'unknown'
|
||||
})
|
||||
return jsonify(procs)
|
||||
return jsonify(procs[:7])
|
||||
except Exception as e:
|
||||
return jsonify([]), 200
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue