|
|
@ -20,10 +20,13 @@ def get_gpus_info(error_dict): |
|
|
|
gpu_name = gpu_name.replace('NVIDIA ', '').replace('GeForce ', '') |
|
|
|
process_list = list() |
|
|
|
for process_info in gpu_info['processes']: |
|
|
|
cmd = process_info['command'] |
|
|
|
if 'full_command' in process_info: |
|
|
|
cmd = ' '.join(process_info["full_command"]) |
|
|
|
process_list.append({ |
|
|
|
"user": process_info['username'], |
|
|
|
"memory": process_info['gpu_memory_usage'], |
|
|
|
"cmd": ' '.join(process_info["full_command"]) |
|
|
|
"cmd": cmd |
|
|
|
}) |
|
|
|
|
|
|
|
# 加到list中 |
|
|
@ -37,7 +40,7 @@ def get_gpus_info(error_dict): |
|
|
|
"process_list": process_list |
|
|
|
}) |
|
|
|
except Exception as e: |
|
|
|
error_dict['gpu'] = e |
|
|
|
error_dict['memory'] = f'{e}' |
|
|
|
|
|
|
|
return result_list |
|
|
|
|
|
|
@ -86,7 +89,7 @@ def get_cpu_info(error_dict): |
|
|
|
result_dict["core_occupy_list"] = psutil.cpu_percent(interval=None, percpu=True) |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
error_dict['cpu'] = e |
|
|
|
error_dict['memory'] = f'{e}' |
|
|
|
|
|
|
|
return result_dict |
|
|
|
|
|
|
@ -104,7 +107,7 @@ def get_storages_info(error_dict, path_list): |
|
|
|
} |
|
|
|
result_list.append(tmp_res) |
|
|
|
except Exception as e: |
|
|
|
error_dict['storage'] = e |
|
|
|
error_dict['memory'] = f'{e}' |
|
|
|
|
|
|
|
return result_list |
|
|
|
|
|
|
@ -116,7 +119,7 @@ def get_memory_info(error_dict): |
|
|
|
result_dict["total"] = mem.total / 1024 |
|
|
|
result_dict["used"] = mem.used / 1024 |
|
|
|
except Exception as e: |
|
|
|
error_dict['memory'] = e |
|
|
|
error_dict['memory'] = f'{e}' |
|
|
|
|
|
|
|
return result_dict |
|
|
|
|
|
|
@ -125,37 +128,39 @@ last_network_stats = None |
|
|
|
last_network_time = None |
|
|
|
def get_networks_info(error_dict): |
|
|
|
result_list = list() |
|
|
|
# try: |
|
|
|
global last_network_stats |
|
|
|
global last_network_time |
|
|
|
current_stats = psutil.net_io_counters(pernic=True) |
|
|
|
|
|
|
|
if last_network_stats is None: |
|
|
|
# 第一次检测 |
|
|
|
for k in current_stats.keys(): |
|
|
|
if k == 'lo': |
|
|
|
continue |
|
|
|
result_list.append({ |
|
|
|
"name": k, |
|
|
|
"default": False, |
|
|
|
"in": 0, |
|
|
|
"out": 0 |
|
|
|
}) |
|
|
|
else: |
|
|
|
time_interval = time.time() - last_network_time |
|
|
|
for k in current_stats.keys(): |
|
|
|
if k == 'lo': |
|
|
|
continue |
|
|
|
result_list.append({ |
|
|
|
"name": k, |
|
|
|
"default": False, |
|
|
|
"in": (current_stats[k].bytes_recv - last_network_stats[k].bytes_recv) / time_interval / 1000, |
|
|
|
"out": (current_stats[k].bytes_sent - last_network_stats[k].bytes_sent) / time_interval / 1000 |
|
|
|
}) |
|
|
|
try: |
|
|
|
global last_network_stats |
|
|
|
global last_network_time |
|
|
|
current_stats = psutil.net_io_counters(pernic=True) |
|
|
|
|
|
|
|
if last_network_stats is None: |
|
|
|
# 第一次检测 |
|
|
|
for k in current_stats.keys(): |
|
|
|
if k == 'lo': |
|
|
|
continue |
|
|
|
result_list.append({ |
|
|
|
"name": k, |
|
|
|
"default": False, |
|
|
|
"in": 0, |
|
|
|
"out": 0 |
|
|
|
}) |
|
|
|
else: |
|
|
|
time_interval = time.time() - last_network_time |
|
|
|
for k in current_stats.keys(): |
|
|
|
if k == 'lo': |
|
|
|
continue |
|
|
|
result_list.append({ |
|
|
|
"name": k, |
|
|
|
"default": False, |
|
|
|
"in": (current_stats[k].bytes_recv - last_network_stats[k].bytes_recv) / time_interval / 1000, |
|
|
|
"out": (current_stats[k].bytes_sent - last_network_stats[k].bytes_sent) / time_interval / 1000 |
|
|
|
}) |
|
|
|
|
|
|
|
# 记录信息下次用 |
|
|
|
last_network_stats = current_stats |
|
|
|
last_network_time = time.time() |
|
|
|
# 记录信息下次用 |
|
|
|
last_network_stats = current_stats |
|
|
|
last_network_time = time.time() |
|
|
|
except Exception as e: |
|
|
|
error_dict['memory'] = f'{e}' |
|
|
|
|
|
|
|
return result_list |
|
|
|
|
|
|
|