标题
使用 Paramiko 和 Tkinter 实现远程服务器信息采集工具
简介
这篇文档介绍了一款使用 Paramiko、Tkinter 和 Openpyxl 开发的远程服务器信息采集工具。用户可以通过一个简单的图形界面对多个服务器执行CPU、内存、网络、磁盘及GPU等数据的采集,并将结果保存至Excel文件中。
功能特点
- 通过SSH连接远程服务器采集信息
- 支持多种信息类型:内存、CPU、磁盘IO、网络信息及GPU信息
- 数据自动保存至Excel文件,并提供合并功能
- 支持多种GPU类型(NVIDIA、XPU、Tianshu)
- 提供图形用户界面,简化操作
环境要求
- Python 3.x
- Required Python libraries: Paramiko, Tkinter, Openpyxl, Pandas
安装步骤
安装 Python 及 必要的第三方库
确保系统上安装了Python,您可以通过以下命令检查Python版本:
python –version
接着安装所需第三方库:
pip install paramiko openpyxl pandas
运行代码
将代码保存为Python文件(如 server_info_collector.py),然后运行:
python server_info_collector.py
使用图形用户界面
程序启动后,会弹出一个对话框要求输入服务器相关信息,包括:
- 服务器IP
- 用户名
- 密码
- 选择盘名称(用逗号分隔)
- GPU型号
- 持续运行时间(秒)
- 信息采集间隔(秒)
根据您的需求输入相应的参数,然后确认,程序会自动进行数据收集并存储。
使用说明
开始数据采集
在填写好所需信息并确认后,程序将根据指定的配置开始从目标服务器采集数据。
数据的存储和查看
采集完成后,程序会将数据保存到当前运行目录下的多个Excel文件中:
- memory_info.xlsx – 内存信息
- cpu_info.xlsx – CPU 信息
- network_info.xlsx – 网络信息
- disk_io_info.xlsx – 硬盘IO信息
- nvidia_gpu_info.xlsx, xpu_gpu_info.xlsx, tianshu_gpu_info.xlsx – 不同类型的GPU信息
最后,程序将各个文件合并为 merged_file.xlsx。
停止和关闭
完成数据采集后,点击图形界面的关闭按钮即可退出程序。
注意事项
- 确保所连接的服务器对SSH连接的IP是开放的。
- 要提供正确的用户名和密码以获得访问权限。
潜在问题和调试
- 如果出现无法连接的问题,请检查主机IP和网络连接是否正常。
- 如果获取GPU信息失败,请检查服务器上是否安装对应的管理工具(例如 nvidia-smi 对于NVIDIA GPU)。
结论
这款信息采集工具提供了一种高效、便捷的方式来获取远程服务器上的关键信息,适合日常监控和性能分析使用。
import paramiko
from openpyxl import load_workbook, Workbook
import tkinter as tk
from tkinter import simpledialog
import time
import os
import datetime
import pandas as pd
import warnings
import multiprocessing
warnings.filterwarnings(action='ignore',module='.*paramiko.*')
# Initialize the global parameters storage
last_inputs = {
"server_ip": "",
"username": "",
"password": "",
"selected_devices": "",
"selected_gpus": "",
"total_run_time": ""
}
class CustomDialog(tk.simpledialog.Dialog):
def __init__(self, master, title=None):
self.initial_values = last_inputs
super().__init__(master, title)
def body(self, master):
tk.Label(master, text="服务器IP:").grid(row=0)
tk.Label(master, text="用户名:").grid(row=1)
tk.Label(master, text="密码:").grid(row=2)
tk.Label(master, text="选择盘名称(用逗号分隔):").grid(row=3)
tk.Label(master, text="GPU型号:").grid(row=4)
tk.Label(master, text="持续运行时间(秒):").grid(row=5)
tk.Label(master, text="信息采集间隔(秒):").grid(row=6) # 新增输入框标签
self.e1 = tk.Entry(master)
self.e2 = tk.Entry(master)
self.e3 = tk.Entry(master)
self.e4 = tk.Entry(master)
self.e5 = tk.Entry(master)
self.e6 = tk.Entry(master)
self.e7 = tk.Entry(master) # 新增输入框
self.e1.grid(row=0, column=1)
self.e2.grid(row=1, column=1)
self.e3.grid(row=2, column=1)
self.e4.grid(row=3, column=1)
self.e5.grid(row=4, column=1)
self.e6.grid(row=5, column=1)
self.e7.grid(row=6, column=1) # 新增输入框位置
self.e1.insert(0, self.initial_values["server_ip"])
self.e2.insert(0, self.initial_values["username"])
self.e3.insert(0, self.initial_values["password"])
self.e4.insert(0, self.initial_values["selected_devices"])
self.e5.insert(0, self.initial_values["selected_gpus"])
self.e6.insert(0, self.initial_values["total_run_time"])
self.e7.insert(0, self.initial_values.get("interval", "5")) # 默认5秒
return self.e1
def apply(self):
global last_inputs
server_ip = self.e1.get()
username = self.e2.get()
password = self.e3.get()
selected_devices = [d.strip() for d in self.e4.get().split(',')]
selected_gpus = [gpu.strip() for gpu in self.e5.get().split(',')]
total_run_time = self.e6.get()
interval = self.e7.get() # 获取新的输入值
self.result = server_ip, username, password, selected_devices, selected_gpus, total_run_time, interval
# Update global last_inputs
last_inputs["server_ip"] = server_ip
last_inputs["username"] = username
last_inputs["password"] = password
last_inputs["selected_devices"] = self.e4.get()
last_inputs["selected_gpus"] = self.e5.get()
last_inputs["total_run_time"] = total_run_time
last_inputs["interval"] = interval # 保存新的输入值
def get_memory_info(server_ip, username, password, total_run_time, interval):
start_time = time.time()
file_path = 'memory_info.xlsx'
headers = ['Time', 'Total', 'Used', 'Free', 'Shared', 'Buff/Cache', 'Available']
wb, ws = initialize_workbook(file_path, headers)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
# 获取时间信息
stdin, stdout, stderr = ssh.exec_command('date +%T')
current_time = stdout.read().decode().strip()
# 获取内存信息
stdin, stdout, stderr = ssh.exec_command('free -g')
memory_info = stdout.read().decode().split('\\n')
memory_values = []
for line in memory_info:
if line.startswith('Mem:'):
memory_values = line.split()[1:]
# 组合内存信息数据
memory_data = [current_time] + memory_values
ws.append(memory_data)
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'Memory information of server {server_ip} has been appended to the file {file_path}.')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"An error occurred: {e}")
def get_cpu_info(server_ip, username, password, total_run_time, interval):
start_time = time.time()
file_path = 'cpu_info.xlsx'
headers = ['Time', 'CPU', '%idle']
wb, ws = initialize_workbook(file_path, headers)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
stdin, stdout, stderr = ssh.exec_command(f'timeout {interval} mpstat -P ALL 1 | tail -n +4')
frequency_info = stdout.readlines()
for info in frequency_info:
if info.strip():
data = info.split()
time_info = data[0] + ' ' + data[1]
cpu_idle_percentage = data[–1]
cpu_info = [time_info, data[2], cpu_idle_percentage]
ws.append(cpu_info)
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'CPU information of server {server_ip} has been appended to the file {file_path}.')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"An error occurred: {e}")
def get_network_info(server_ip, username, password, total_run_time, interval):
start_time = time.time()
file_path = 'network_info.xlsx'
headers = ['Time', 'Interface', 'RX Rate (MB/s)', 'TX Rate (MB/s)']
wb, ws = initialize_workbook(file_path, headers)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
stdin, stdout, stderr = ssh.exec_command('ifconfig -a')
net_info = stdout.read().decode().split('\\n')
for line in net_info:
if line.strip().startswith('en') or line.strip().startswith('ib'):
interface = line.strip().split(':')[0]
current_time, rx_rate, tx_rate = get_rdma_data(ssh, interface)
if rx_rate is not None and tx_rate is not None:
ws.append([current_time, interface, rx_rate, tx_rate])
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'Network information of server {server_ip} has been appended to the file {file_path}.')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"An error occurred: {e}")
def get_rdma_data(ssh, interface):
initial_time, initial_data = get_rdma_bytes(ssh, interface)
time.sleep(1)
final_time, final_data = get_rdma_bytes(ssh, interface)
if 'rx' in initial_data and 'rx' in final_data and 'tx' in initial_data and 'tx' in final_data:
rx_diff = final_data['rx'] – initial_data['rx']
tx_diff = final_data['tx'] – initial_data['tx']
rx_rate = rx_diff / 1024 / 1024
tx_rate = tx_diff / 1024 / 1024
return final_time, rx_rate, tx_rate
else:
print(f"RDMA data not available for interface {interface}. Skipping calculation.")
return None, None, None
def get_rdma_bytes(ssh, interface):
_, stdout, _ = ssh.exec_command('date +%T')
current_time = stdout.read().decode().strip()
_, stdout, _ = ssh.exec_command(f'ethtool -S {interface} | grep -i rdma')
rdma_info = stdout.read().decode()
lines = rdma_info.split('\\n')
data = {}
for line in lines:
if 'rx_vport_rdma_unicast_bytes' in line:
data['rx'] = int(line.split(':')[1].strip())
elif 'tx_vport_rdma_unicast_bytes' in line:
data['tx'] = int(line.split(':')[1].strip())
return current_time, data
def get_nvidia_gpu_info(server_ip, username, password, total_run_time, interval):
start_time = time.time()
file_path = 'nvidia_gpu_info.xlsx'
headers = ['Time', 'GPU', 'Temp', 'Power Draw', 'Max Power Limit', 'Tx Throughput',
'Rx Throughput', 'GPU-Util', 'Memory-Used', 'Memory-Total',
'SM_Clocks', 'SM_MaxClocks', 'Memory_Clocks', 'Memory_MaxClocks']
wb, ws = initialize_workbook(file_path, headers)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
temp_file = "/tmp/gpu_info.txt"
combined_command = """
nvidia-smi -q > {temp_file} &&
echo "##TIMESTAMP##" && grep -i Timestamp {temp_file} | grep -v 'Latest Timestamp' | sed 's/.*: //' &&
echo "##MINORNUMBER##" && grep 'Minor Number' {temp_file} | awk -F ':' '{{print $2}}' &&
echo "##TEMPERATURE##" && grep -i 'GPU Current Temp' {temp_file} | sed 's/.*: //' &&
echo "##POWERDRAW##" && sed -n -e '/GPU Power Readings/,/Max Power Limit/p' {temp_file} | grep -E 'Power Draw' | sed 's/.*: //' &&
echo "##MAXPOWER##" && sed -n -e '/GPU Power Readings/,/Max Power Limit/p' {temp_file} | grep -E 'Max Power Limit' | sed 's/.*: //' &&
echo "##TXTHROUGHPUT##" && grep -i 'Tx Throughput' {temp_file} | sed 's/.*: //' &&
echo "##RXTHROUGHPUT##" && grep -i 'Rx Throughput' {temp_file} | sed 's/.*: //' &&
echo "##GPUUTIL##" && sed -n -e '/Utilization/,/Gpu/p' {temp_file} | grep -E 'Gpu' | sed 's/.*: //' &&
echo "##MEMUSED##" && sed -n -e '/FB Memory Usage/, /Free/p' {temp_file} | grep -E 'Used' | sed 's/.*: //' &&
echo "##MEMTOTAL##" && sed -n -e '/FB Memory Usage/, /Free/p' {temp_file} | grep -E 'Total' | sed 's/.*: //' &&
echo "##SMCLOCKS##" && awk '/^ *Clocks *$/{{p=1; count=0; next}} /^$/{{p=0}} p{{if (count<4) {{print; count++}}}}' {temp_file} | awk -F ':' '/SM/{{gsub(/^[ \\\\\\\\t]+|[ \\\\\\\\t]+$/, "", $2); print $2}}' &&
echo "##SMMAXCLOCKS##" && awk '/^ *Max Clocks *$/{{p=1; count=0; next}} /^$/{{p=0}} p{{if (count<4) {{print; count++}}}}' {temp_file} | awk -F ':' '/SM/{{gsub(/^[ \\\\\\\\t]+|[ \\\\\\\\t]+$/, "", $2); print $2}}' &&
echo "##MEMCLOCKS##" && awk '/^ *Clocks *$/{{p=1; count=0; next}} /^$/{{p=0}} p{{if (count<4) {{print; count++}}}}' {temp_file} | awk -F ':' '/Memory/{{gsub(/^[ \\\\\\\\t]+|[ \\\\\\\\t]+$/, "", $2); print $2}}' &&
echo "##MEMMAXCLOCKS##" && awk '/^ *Max Clocks *$/{{p=1; count=0; next}} /^$/{{p=0}} p{{if (count<4) {{print; count++}}}}' {temp_file} | awk -F ':' '/Memory/{{gsub(/^[ \\\\\\\\t]+|[ \\\\\\\\t]+$/, "", $2); print $2}}'
""".format(temp_file=temp_file)
stdin, stdout, stderr = ssh.exec_command(combined_command.strip())
output = stdout.read().decode('utf-8').strip()
error = stderr.read().decode('utf-8').strip()
if error:
print(f"Command execution error: {error}")
return
markers = [
"##TIMESTAMP##", "##MINORNUMBER##", "##TEMPERATURE##", "##POWERDRAW##",
"##MAXPOWER##", "##TXTHROUGHPUT##", "##RXTHROUGHPUT##", "##GPUUTIL##",
"##MEMUSED##", "##MEMTOTAL##", "##SMCLOCKS##", "##SMMAXCLOCKS##",
"##MEMCLOCKS##", "##MEMMAXCLOCKS##"
]
data_dict = {marker: [] for marker in markers}
current_marker = None
for line in output.splitlines():
if line in markers:
current_marker = line
elif current_marker:
data_dict[current_marker].append(line)
max_row = ws.max_row
for i, marker in enumerate(markers, start=1):
data_column = data_dict.get(marker, None)
if data_column:
for j, data in enumerate(data_column, start=1):
ws.cell(row=max_row + j, column=i, value=data.strip())
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'NVIDIA GPU information has been appended to the file {file_path}')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"An error occurred: {e}")
def initialize_workbook(file_path, headers):
if not os.path.exists(file_path):
wb = Workbook()
ws = wb.active
ws.append(headers)
wb.save(file_path)
else:
wb = load_workbook(file_path)
ws = wb.active
return wb, ws
def collect_disk_io_info(server_ip, username, password, devices, total_run_time, interval):
start_time = time.time()
file_path = 'disk_io_info.xlsx'
if not os.path.exists(file_path):
wb = Workbook() # 创建一个新的 Workbook 对象
ws = wb.active
wb.save(file_path)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
for device in devices:
command = f"iostat -xm 1 -d {device} -t 10 | awk 'NR>2 {{print $1, $2, $3, $9}}'"
# print("执行的命令是:", command)
stdin, stdout, stderr = ssh.exec_command(command)
iostat_output = stdout.readlines() # 获取命令的标准输出的所有行
ws.append([f"Iostat output for device: {device}"])
# 合并单元格,将单元格的宽度合并为4个单元格
ws.merge_cells(start_row=ws.max_row, start_column=1, end_row=ws.max_row, end_column=4)
for line in iostat_output:
row_data = line.strip().split() # 使用 split() 方法根据空格拆分数据
ws.append(row_data) # 将拆分后的数据写入表格中
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'Disk IO information of server {server_ip} has been appended to the file {file_path}.')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"Error occurred: {e}")
def get_xpu_gpu_info(server_ip, username, password, total_run_time, interval):
start_time = time.time()
file_path = 'xpu_gpu_info.xlsx'
headers = ['Time', 'DevID', 'Temp', 'Power Draw', 'Power Limit', 'GPU-Util', 'Memory-Used', 'Memory-Total']
wb, ws = initialize_workbook(file_path, headers)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
commands = [
"xpu-smi -q | grep -i Timestamp | grep -v 'Latest Timestamp' | sed 's/.*: //'",
"xpu-smi -q |grep -i 'Minor Number' | awk -F ':' '{print $2}'",
"xpu-smi -q | grep -i 'XPU Current Temp' | sed 's/.*: //'",
"xpu-smi -q | sed -n -e '/Power Readings/,/Power Draw/p' | grep -E 'Power Draw' | sed 's/.*: //'",
"xpu-smi -q | sed -n -e '/Power Readings/,/Enforced Power Limit/p' | grep -E 'Enforced Power Limit' | sed 's/.*: //'",
"xpu-smi -q | sed -n -e '/Utilization/,/Xpu/p' | grep -E 'Xpu' | sed 's/.*: //'",
"xpu-smi -q | sed -n -e '/Memory Usage/, /Free/p' |grep -E 'Used'| sed 's/.*: //'",
"xpu-smi -q | sed -n -e '/Memory Usage/, /Free/p' |grep -E 'Total'| sed 's/.*: //'",
]
max_row = ws.max_row
for i, command in enumerate(commands, start=1):
stdin, stdout, stderr = ssh.exec_command(command)
output = stdout.read().decode('utf-8').strip()
if output:
gpu_info = output.split('\\n')
for j, info in enumerate(gpu_info, start=1):
ws.cell(row=max_row + j + 1, column=i, value=info.strip())
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'GPU information of server {server_ip} has been appended to the file {file_path}.')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"An error occurred: {e}")
def get_tianshu_gpu_info(server_ip, username, password, total_run_time, interval):
start_time = time.time()
file_path = 'tianshu_gpu_info.xlsx'
headers = ['Time', 'DevID', 'Temp', 'Power Draw', 'Power Limit', 'GPU-Util', 'Memory-Used', 'Memory-Total']
wb, ws = initialize_workbook(file_path, headers)
try:
while time.time() – start_time < total_run_time:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_ip, username=username, password=password)
commands = [
"ixsmi -q | grep -i Timestamp | grep -v 'Latest Timestamp' | sed 's/.*: //'",
"ixsmi -q |grep -i 'Minor Number' | awk -F ':' '{print $2}'",
"ixsmi -q | grep -i 'GPU Current Temp' | sed 's/.*: //'",
"ixsmi -q | sed -n -e '/Power Readings/,/GPU Power Draw/p' | grep -E 'Power Draw' | sed 's/.*: //'",
"ixsmi -q | sed -n -e '/Power Readings/,/GPU Power Limit/p' | grep -E 'Power Limit' | sed 's/.*: //'",
"ixsmi -q | sed -n -e '/Utilization/,/Gpu/p' | grep -E 'Gpu' | sed 's/.*: //'",
"ixsmi -q | sed -n -e '/Memory Usage/, /Free/p' |grep -E 'Used'| sed 's/.*: //'",
"ixsmi -q | sed -n -e '/Memory Usage/, /Free/p' |grep -E 'Total'| sed 's/.*: //'",
]
max_row = ws.max_row
for i, command in enumerate(commands, start=1):
stdin, stdout, stderr = ssh.exec_command(command)
output = stdout.read().decode('utf-8').strip()
if output:
gpu_info = output.split('\\n')
for j, info in enumerate(gpu_info, start=1):
ws.cell(row=max_row + j + 1, column=i, value=info.strip())
ssh.close()
time.sleep(interval)
wb.save(file_path)
print(f'GPU information of server {server_ip} has been appended to the file {file_path}.')
except paramiko.SSHException as e:
print(f"SSH connection error: {e}")
print('SSH connection error, please check if the server IP, username, and password are correct.')
except Exception as e:
print(f"An error occurred: {e}")
def process_excel(file_path):
# 读取原始表格
file_path = 'disk_io_info.xlsx'
wb = load_workbook(file_path)
ws = wb.active
data = []
collecting_data = False
current_time = ""
# 逐行检查数据,提取需要的信息
for row in ws.iter_rows(values_only=True):
if row[0] and '/' in str(row[0]): # 判断是否为日期时间行
current_time = f"{row[0]} {row[1]}" # 将日期和时间拼接起来
elif row[0] == "Device" and row[1] == "r/s" and row[2] == "rMB/s" and row[3] == "wMB/s": # 确认是数据标题行
collecting_data = True
elif collecting_data and row[0] and row[1] and row[2] and row[3]: # 确认是数据行
device = row[0]
rMB_s = row[2]
wMB_s = row[3]
data.append([current_time, device, rMB_s, wMB_s])
# 如果有数据才继续创建新的表格
if data:
# 构建新的数据表格
new_df = pd.DataFrame(data, columns=['Time', 'Device', 'rMB/s', 'wMB/s'])
# 将新数据写入新的 Excel 表格
new_file_path = 'new_disk_io_info.xlsx'
new_df.to_excel(new_file_path, index=False)
print(f"新表格生成完成: {new_file_path}")
# 删除原始 Excel 文件
os.remove(file_path)
print(f"原始 Excel 文件 {file_path} 已被删除")
else:
print("没有找到符合条件的数据")
def merge_excel_files(output_file_name):
merged_wb = Workbook()
file_list = [file for file in os.listdir() if file.endswith('.xlsx')]
for file_name in file_list:
wb = load_workbook(filename=file_name, data_only=True)
ws = wb.active
new_ws = merged_wb.create_sheet(title=os.path.splitext(file_name)[0])
for row in ws.iter_rows(values_only=True):
new_ws.append(row)
# Save the merged Excel file
merged_wb.remove(merged_wb.active)
merged_wb.save(output_file_name)
print(f'Merged Excel files saved to: {output_file_name}')
def main():
root = tk.Tk()
root.withdraw()
while True:
dialog = CustomDialog(root, "请输入服务器信息")
if dialog.result:
server_ip, username, password, selected_devices, selected_gpus, total_run_time, interval = dialog.result
interval = int(interval) # 确保间隔时间是整数
total_run_time = int(total_run_time)
processes = []
if selected_devices:
p_disk_io = multiprocessing.Process(target=collect_disk_io_info, args=(
server_ip, username, password, selected_devices, total_run_time, interval))
processes.append(p_disk_io)
p_memory = multiprocessing.Process(target=get_memory_info,
args=(server_ip, username, password, total_run_time, interval))
processes.append(p_memory)
p_cpu = multiprocessing.Process(target=get_cpu_info,
args=(server_ip, username, password, total_run_time, interval))
processes.append(p_cpu)
p_network = multiprocessing.Process(target=get_network_info,
args=(server_ip, username, password, total_run_time, interval))
processes.append(p_network)
for selected_gpu in selected_gpus:
if selected_gpu.startswith("xpu"):
p_xpu_gpu = multiprocessing.Process(target=get_xpu_gpu_info,
args=(server_ip, username, password, total_run_time, interval))
processes.append(p_xpu_gpu)
elif selected_gpu.startswith("nvidia"):
p_nvidia_gpu = multiprocessing.Process(target=get_nvidia_gpu_info, args=(
server_ip, username, password, total_run_time, interval))
processes.append(p_nvidia_gpu)
elif selected_gpu.startswith("tianshu"):
p_tianshu_gpu = multiprocessing.Process(target=get_tianshu_gpu_info, args=(
server_ip, username, password, total_run_time, interval))
processes.append(p_tianshu_gpu)
else:
print(f"Unknown GPU type: {selected_gpu}")
# 启动所有进程
for process in processes:
process.start()
# 等待所有进程完成
for process in processes:
process.join()
file_path = 'disk_io_info.xlsx'
if os.path.exists(file_path):
process_excel(file_path)
else:
print(f"原始 Excel 文件 {file_path} 不存在,无法执行 process_excel 函数。")
merge_excel_files('merged_file.xlsx')
label = tk.Label(root, text="信息已收集并保存至相应文件")
label.pack()
else:
break
close_button = tk.Button(root, text="关闭", command=root.destroy)
close_button.pack()
root.mainloop()
if __name__ == "__main__":
main()
评论前必须登录!
注册