@@ -16,13 +16,21 @@ def get_server_info(name, hostname, port, username, password):
16
16
client .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
17
17
client .connect (hostname , port = port , username = username , password = password )
18
18
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
+
19
27
# 获取CPU信息
20
28
stdin , stdout , stderr = client .exec_command ("cat /proc/cpuinfo | grep 'model name' | uniq" )
21
29
cpu_info = stdout .read ().decode ().strip ()
22
30
23
31
# 获取CPU占用量
24
32
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 () + "%"
26
34
27
35
# 获取CPU核心数
28
36
stdin , stdout , stderr = client .exec_command ("nproc" )
@@ -35,21 +43,17 @@ def get_server_info(name, hostname, port, username, password):
35
43
# 获取硬盘信息
36
44
stdin , stdout , stderr = client .exec_command ("df -h | awk '$NF==\" /\" {printf \" %d/%dGB (%s)\" , $3,$2,$5}'" )
37
45
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
-
44
46
45
47
# 打印服务器信息
46
- print (f"服务器 { name } 当前信息:" )
48
+ print (f"{ name } 当前信息:" )
49
+ print (f"系统版本: { debian_version } " )
50
+ print (f"Linux版本: { kernel_version } " )
47
51
print (f"CPU架构: { cpu_info } " )
48
52
print (f"CPU占用: { cpu_usage } " )
49
53
print (f"CPU核心数: { cpu_cores } " )
50
54
print (f"内存占用: { mem_info } " )
51
55
print (f"硬盘占用: { disk_info } " )
52
- #print(f"流量消耗: {net_info}")
56
+
53
57
print ()
54
58
55
59
# 关闭 SSH 连接
@@ -67,4 +71,4 @@ def get_server_info(name, hostname, port, username, password):
67
71
get_server_info (name , hostname , port , username , password )
68
72
69
73
# 等待用户按下任意键后关闭窗口
70
- input ("按任意键关闭窗口..." )
74
+ input ("按任意键关闭窗口..." )
0 commit comments