腳本內(nèi)容如下:
下面所以當(dāng)圖片代碼都是在一個(gè)文件中的住涉,當(dāng)然也可把函數(shù)拆解出來使用木人。
image
容量裝換工具
image
獲取 CPU 數(shù)據(jù)的函數(shù)
image
打印 CPU 數(shù)據(jù)的函數(shù)
image
獲取內(nèi)存數(shù)據(jù)的函數(shù)
image
打印內(nèi)存數(shù)據(jù)的函數(shù)
image
獲取網(wǎng)卡數(shù)據(jù)的函數(shù)
image
image
image
addrs
數(shù)據(jù)結(jié)構(gòu)解析說明(這部分不屬于腳本中的代碼)
addrs 是個(gè)列表信柿,其數(shù)據(jù)像下面的樣子:
[snic(family=<AddressFamily.AF_INET: 2>,
address='172.16.153.134',
netmask='255.255.255.0',
broadcast='172.16.153.255',
ptp=None),
snic(family=<AddressFamily.AF_INET6: 10>,
address='fe80::20c:29ff:fe11:610a%eth0',
netmask='ffff:ffff:ffff:ffff::',
broadcast=None,
ptp=None),
snic(family=<AddressFamily.AF_PACKET: 17>,
address='00:0c:29:11:61:0a',
netmask=None,
broadcast='ff:ff:ff:ff:ff:ff',
ptp=None)
]
上面的 get_net_info()
函數(shù)最終得到的信息(這部分不屬于腳本中的代碼):
{
'eth0': {'nic_stat': True, 'ip': '172.16.153.160', 'netmask': '255.255.255.0'},
'eth1': {'nic_stat': True, 'ip': '10.18.43.24', 'netmask': '255.255.255.0'},
'io_info': {'bytes_sent': '72.4G', 'bytes_recv': '3.2G', 'packe_sent': 51617898,'packe_recv': 23959477}
}
為了實(shí)驗(yàn)效果,eth2 是關(guān)閉的網(wǎng)卡醒第,命令:
ifdown eth2
; 重新啟動(dòng)此網(wǎng)卡執(zhí)行命令:ifup eth2
打印網(wǎng)卡數(shù)據(jù)的函數(shù)
image
image
主邏輯函數(shù)
image
運(yùn)行腳本渔嚷,看效果
image.png
image.png
image
image
image