You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
6.1 KiB
164 lines
6.1 KiB
1 month ago
|
|
||
|
#获取supervisor信息
|
||
|
def get_supervisor_info(data):
|
||
|
# 生成表格数据
|
||
|
supervisor_data = []
|
||
|
|
||
|
# 计算 Supervisor 的数量
|
||
|
supervisor_count = sum(1 for node in data if node["node_type"] == "Supervisor")
|
||
|
|
||
|
# 获取 Supervisor 的 ip_address
|
||
|
supervisor_ip_address = next((node["ip_address"] for node in data if node["node_type"] == "Supervisor"), "")
|
||
|
|
||
|
# 计算 CPU-Info
|
||
|
cpu_info_value = f'{data[0]["cpu_count"] - data[0]["cpu_available"]:.2f}'
|
||
|
cpu_info_other = data[0]["cpu_count"]
|
||
|
|
||
|
# 计算 CPU-Memory-Info
|
||
|
cpu_memory_info_value = (data[0]["mem_total"] - data[0]["mem_available"]) / 1024 / 1024
|
||
|
cpu_memory_info_other = data[0]["mem_total"] / 1024 / 1024
|
||
|
|
||
|
# 填充表格数据
|
||
|
supervisor_data.append({
|
||
|
'字段1': "Count",
|
||
|
'字段2': supervisor_count,
|
||
|
'字段3': "", # other 为空
|
||
|
})
|
||
|
supervisor_data.append({
|
||
|
'字段1': "Address",
|
||
|
'字段2': supervisor_ip_address,
|
||
|
'字段3': "", # other 为空
|
||
|
})
|
||
|
supervisor_data.append({
|
||
|
'字段1': "CPU-Info",
|
||
|
'字段2': cpu_info_value,
|
||
|
'字段3': cpu_info_other,
|
||
|
})
|
||
|
supervisor_data.append({
|
||
|
'字段1': "CPU-Memory-Info",
|
||
|
'字段2': f'{cpu_memory_info_value:.2f}',
|
||
|
'字段3': f'{cpu_memory_info_other:.2f}',
|
||
|
})
|
||
|
return supervisor_data
|
||
|
|
||
|
def get_workers_info(data):
|
||
|
# 生成表格数据
|
||
|
workers_data = []
|
||
|
|
||
|
# 计算 Worker 的数量
|
||
|
workers_count = sum(1 for node in data if node["node_type"] == "Worker")
|
||
|
|
||
|
# 计算所有 Worker 的 CPU 信息
|
||
|
total_cpu_count = sum(node["cpu_count"] for node in data if node["node_type"] == "Worker")
|
||
|
total_cpu_available = sum(node["cpu_available"] for node in data if node["node_type"] == "Worker")
|
||
|
cpu_info_value = f'{total_cpu_count - total_cpu_available:.2f}'
|
||
|
cpu_info_other = total_cpu_count
|
||
|
|
||
|
# 计算所有 Worker 的 CPU 内存信息
|
||
|
total_mem_total = sum(node["mem_total"] for node in data if node["node_type"] == "Worker")
|
||
|
total_mem_available = sum(node["mem_available"] for node in data if node["node_type"] == "Worker")
|
||
|
cpu_memory_info_value = (total_mem_total - total_mem_available) / 1024 / 1024
|
||
|
cpu_memory_info_other = total_mem_total / 1024 / 1024
|
||
|
|
||
|
# 计算所有 Worker 的 GPU 数量
|
||
|
total_gpu_count = sum(node["gpu_count"] for node in data if node["node_type"] == "Worker")
|
||
|
|
||
|
# 计算所有 Worker 的 GPU 内存信息
|
||
|
total_gpu_vram_total = sum(node["gpu_vram_total"] for node in data if node["node_type"] == "Worker")
|
||
|
total_gpu_vram_available = sum(node["gpu_vram_available"] for node in data if node["node_type"] == "Worker")
|
||
|
gpu_memory_info_value = (total_gpu_vram_total - total_gpu_vram_available) / 1024 / 1024
|
||
|
gpu_memory_info_other = total_gpu_vram_total / 1024 / 1024
|
||
|
|
||
|
# 填充表格数据
|
||
|
workers_data.append({
|
||
|
'字段1': "Count",
|
||
|
'字段2': workers_count,
|
||
|
'字段3': "", # other 为空
|
||
|
})
|
||
|
workers_data.append({
|
||
|
'字段1': "CPU-Info",
|
||
|
'字段2': cpu_info_value,
|
||
|
'字段3': cpu_info_other,
|
||
|
})
|
||
|
workers_data.append({
|
||
|
'字段1': "CPU-Memory-Info",
|
||
|
'字段2': f'{cpu_memory_info_value:.2f} MB',
|
||
|
'字段3': f'{cpu_memory_info_other:.2f} MB',
|
||
|
})
|
||
|
workers_data.append({
|
||
|
'字段1': "GPU-Count",
|
||
|
'字段2': total_gpu_count,
|
||
|
'字段3': "", # other 为空
|
||
|
})
|
||
|
workers_data.append({
|
||
|
'字段1': "GPU-Memory-Info",
|
||
|
'字段2': f'{gpu_memory_info_value:.2f} MB',
|
||
|
'字段3': f'{gpu_memory_info_other:.2f} MB',
|
||
|
})
|
||
|
|
||
|
return workers_data
|
||
|
|
||
|
def get_worker_detail_info(data):
|
||
|
# 生成表格数据
|
||
|
worker_detail_data = []
|
||
|
|
||
|
# 遍历所有的 Worker 节点
|
||
|
for node in data:
|
||
|
if node["node_type"] == "Worker":
|
||
|
# 获取 Worker 的详细信息
|
||
|
address = node["ip_address"]
|
||
|
cpu_usage = f'{node["cpu_count"] - node["cpu_available"]:.2f}'
|
||
|
cpu_total = node["cpu_count"]
|
||
|
mem_usage = (node["mem_total"] - node["mem_available"]) / 1024 / 1024
|
||
|
mem_total = node["mem_total"] / 1024 / 1024
|
||
|
gpu_count = node["gpu_count"]
|
||
|
gpu_mem_usage = (node["gpu_vram_total"] - node["gpu_vram_available"]) / 1024 / 1024
|
||
|
gpu_mem_total = node["gpu_vram_total"] / 1024 / 1024
|
||
|
|
||
|
# 填充表格数据
|
||
|
worker_detail_data.append({
|
||
|
'字段1': "Worker",
|
||
|
'字段2': address,
|
||
|
'字段3': f'{cpu_usage} cores',
|
||
|
'字段4': f'{cpu_total} cores',
|
||
|
'字段5': f'{mem_usage:.2f} MB',
|
||
|
'字段6': f'{mem_total:.2f} MB',
|
||
|
'字段7': gpu_count,
|
||
|
'字段8': f'{gpu_mem_usage:.2f} MB',
|
||
|
'字段9': f'{gpu_mem_total:.2f} MB',
|
||
|
})
|
||
|
|
||
|
return worker_detail_data
|
||
|
|
||
|
|
||
|
# def get_model_run_data(data):
|
||
|
# # 生成表格数据
|
||
|
# mode_run_data = []
|
||
|
|
||
|
# # 遍历所有的 Worker 节点
|
||
|
# for node in data:
|
||
|
# if node["node_type"] == "Worker":
|
||
|
# # 获取 Worker 的详细信息
|
||
|
# address = node["ip_address"]
|
||
|
# cpu_usage = f'{node["cpu_count"] - node["cpu_available"]:.2f}'
|
||
|
# cpu_total = node["cpu_count"]
|
||
|
# mem_usage = (node["mem_total"] - node["mem_available"]) / 1024 / 1024
|
||
|
# mem_total = node["mem_total"] / 1024 / 1024
|
||
|
# gpu_count = node["gpu_count"]
|
||
|
# gpu_mem_usage = (node["gpu_vram_total"] - node["gpu_vram_available"]) / 1024 / 1024
|
||
|
# gpu_mem_total = node["gpu_vram_total"] / 1024 / 1024
|
||
|
|
||
|
# # 填充表格数据
|
||
|
# worker_detail_data.append({
|
||
|
# '字段1': "Worker",
|
||
|
# '字段2': address,
|
||
|
# '字段3': f'{cpu_usage} cores',
|
||
|
# '字段4': f'{cpu_total} cores',
|
||
|
# '字段5': f'{mem_usage:.2f} MB',
|
||
|
# '字段6': f'{mem_total:.2f} MB',
|
||
|
# '字段7': gpu_count,
|
||
|
# '字段8': f'{gpu_mem_usage:.2f} MB',
|
||
|
# '字段9': f'{gpu_mem_total:.2f} MB',
|
||
|
# })
|
||
|
|
||
|
# return worker_detail_data
|