|
import os |
|
import json |
|
import csv |
|
import subprocess |
|
import psutil |
|
|
|
def load_model(): |
|
pass |
|
|
|
def run(): |
|
|
|
try: |
|
|
|
la = round((psutil.getloadavg()[0] / psutil.cpu_count()) * 100) |
|
|
|
|
|
cpu = round(psutil.cpu_percent(percpu=False)) |
|
|
|
|
|
ram = psutil.virtual_memory() |
|
rama = round(ram.available) |
|
ramt = round(ram.total) |
|
ramp = 100 - ram.percent |
|
ramg = round(ram.available / 1073741824) |
|
|
|
|
|
gpu = 0 |
|
vrama = 0 |
|
vramt = 0 |
|
vramp = 0 |
|
vramg = 0 |
|
|
|
cmd = 'nvidia-smi --query-gpu=utilization.gpu,memory.used,memory.total --format=csv,noheader,nounits' |
|
csv = subprocess.run(cmd, shell=True, capture_output=True, text=True).stdout |
|
lines = csv.split("\n") |
|
for line in lines: |
|
if not line: |
|
continue |
|
r = line.split(',') |
|
gpu += round(float(r[0])) |
|
vrama += round(float(r[1])) |
|
vramt += round(float(r[2])) |
|
vramp += round(vrama / vramt * 100) |
|
vramg += round(float(r[1]) / 1024) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = { |
|
'la': la, |
|
'cpu': cpu, |
|
'ram': ramg, |
|
'gpu': gpu, |
|
'vram': vramg, |
|
} |
|
|
|
return res |
|
except Exception as e: |
|
print(e) |
|
return {} |
|
|