Skip to content

Commit c99bc97

Browse files
authored
Update 一键查看所有VPS资源占用.py
1 parent c33c4fb commit c99bc97

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

一键查看所有VPS资源占用.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ def get_server_info(name, hostname, port, username, password):
1616
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
1717
client.connect(hostname, port=port, username=username, password=password)
1818

19+
# 获取Debian系统版本
20+
stdin, stdout, stderr = client.exec_command("cat /etc/os-release | grep PRETTY_NAME | awk -F= '{print $2}' | tr -d '\"'")
21+
debian_version = stdout.read().decode().strip()
22+
23+
# 获取Linux内核版本
24+
stdin, stdout, stderr = client.exec_command("uname -r")
25+
kernel_version = stdout.read().decode().strip()
26+
1927
# 获取CPU信息
2028
stdin, stdout, stderr = client.exec_command("cat /proc/cpuinfo | grep 'model name' | uniq")
2129
cpu_info = stdout.read().decode().strip()
2230

2331
# 获取CPU占用量
2432
stdin, stdout, stderr = client.exec_command("top -bn1 | grep 'Cpu(s)' | awk '{print $2 + $4}'")
25-
cpu_usage = stdout.read().decode().strip()
33+
cpu_usage = stdout.read().decode().strip() + "%"
2634

2735
# 获取CPU核心数
2836
stdin, stdout, stderr = client.exec_command("nproc")
@@ -35,21 +43,17 @@ def get_server_info(name, hostname, port, username, password):
3543
# 获取硬盘信息
3644
stdin, stdout, stderr = client.exec_command("df -h | awk '$NF==\"/\"{printf \"%d/%dGB (%s)\", $3,$2,$5}'")
3745
disk_info = stdout.read().decode().strip()
38-
39-
# 获取网络信息
40-
# stdin, stdout, stderr = client.exec_command("ifconfig eth0 | awk '/RX packets/{rx=$3;rb=$5}/TX packets/{tx=$3;tb=$5}END{printf \"RX:%.2fMB TX:%.2fMB\", (rb/(1024*1024)) , (tb/(1024*1024))}'")
41-
# net_info = stdout.read().decode().strip()
42-
43-
4446

4547
# 打印服务器信息
46-
print(f"服务器 {name} 当前信息:")
48+
print(f"{name} 当前信息:")
49+
print(f"系统版本: {debian_version}")
50+
print(f"Linux版本: {kernel_version}")
4751
print(f"CPU架构: {cpu_info}")
4852
print(f"CPU占用: {cpu_usage}")
4953
print(f"CPU核心数: {cpu_cores}")
5054
print(f"内存占用: {mem_info}")
5155
print(f"硬盘占用: {disk_info}")
52-
#print(f"流量消耗: {net_info}")
56+
5357
print()
5458

5559
# 关闭 SSH 连接
@@ -67,4 +71,4 @@ def get_server_info(name, hostname, port, username, password):
6771
get_server_info(name, hostname, port, username, password)
6872

6973
# 等待用户按下任意键后关闭窗口
70-
input("按任意键关闭窗口...")
74+
input("按任意键关闭窗口...")

0 commit comments

Comments
 (0)