鏍戣帗娲綜PU銆丟PU銆佺鐩樸€佸唴瀛樸€佽礋杞界洃鎺ython鑴氭湰
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏍戣帗娲綜PU銆丟PU銆佺鐩樸€佸唴瀛樸€佽礋杞界洃鎺ython鑴氭湰相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/span' title='span'>span disk one load 鏂囦欢 pytho read 鑾峰彇
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import commands
import os
def main():
# 鏌ョ湅GPU娓╁害
gpu = float(gpu)
print(鈥榞pu Temp: %.2f 鈥?/span> % gpu)
# 鏌ョ湅CPU娓╁害
file = open("/sys/class/thermal/thermal_zone0/temp")
cpu = float(file.read()) / 1000
file.close()
print(鈥榗pu Temp: %2.2f鈥?/span> % cpu)
load_1min = str(os.popen("top -n1 | awk 鈥?load average:/ {print $12}鈥?).readline().strip()).replace(鈥?鈥?/span>, 鈥樷€?/span> )
load_5min = str(os.popen("top -n1 | awk 鈥?load average:/ {print $13}鈥?).readline().strip()).replace(鈥?鈥?/span>, 鈥樷€?/span> )
load_1min=float(load_1min)
load_5min=float(load_5min)
print(鈥樷€?/span>)
print(鈥榣oad_1min: %.2f鈥?/span>%load_1min)
print(鈥榣oad_5min: %.2f鈥?/span>%load_5min)
Ramused = str(os.popen("top -n1 | awk 鈥?KiB/ {print $6}鈥?).readline().strip()).replace(鈥?鈥?/span>, 鈥樷€?/span> )
Ramused = int(Ramused)
Ramused = Ramused / 1000
print(鈥樷€?/span>)
print(鈥楻amused: %d 鈥?/span>%Ramused +鈥?Mb鈥?/span>)
def getDiskSpace():
p = os.popen("df -h /")
i = 0
while 1:
i = i +1
line = p.readline()
if i==2:
return(line.split()[1:5])
# Disk information
DISK_stats = getDiskSpace()
DISK_total = DISK_stats[0].replace(鈥楪鈥?/span>,鈥樷€?/span>)
DISK_used = DISK_stats[1].replace(鈥楪鈥?/span>, 鈥樷€?/span> )
DISK_perc = DISK_stats[3].replace(鈥?鈥?/span>, 鈥樷€?/span> )
print(鈥樷€?/span>)
print(鈥楧ISK_total: 鈥?/span>+str(DISK_total)+鈥?Gb鈥?/span>)
print(鈥楧ISK_used: 鈥?/span>+str(DISK_used)+鈥?Gb鈥?/span>)
print(鈥楧ISK_perc: 鈥?/span>+str(DISK_perc)+鈥?%鈥?/span>)
if __name__ == 鈥榑_main__鈥?/span>:
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import commands
import os
def main():
# 鏌ョ湅GPU娓╁害
gpu = float(gpu)
print(鈥榞pu Temp: %.2f 鈥?/span> % gpu)
# 鏌ョ湅CPU娓╁害
file = open("/sys/class/thermal/thermal_zone0/temp")
cpu = float(file.read()) / 1000
file.close()
print(鈥榗pu Temp: %2.2f鈥?/span> % cpu)
load_1min = str(os.popen("top -n1 | awk 鈥?load average:/ {print $12}鈥?).readline().strip()).replace(鈥?鈥?/span>, 鈥樷€?/span> )
load_5min = str(os.popen("top -n1 | awk 鈥?load average:/ {print $13}鈥?).readline().strip()).replace(鈥?鈥?/span>, 鈥樷€?/span> )
load_1min=float(load_1min)
load_5min=float(load_5min)
print(鈥樷€?/span>)
print(鈥榣oad_1min: %.2f鈥?/span>%load_1min)
print(鈥榣oad_5min: %.2f鈥?/span>%load_5min)
Ramused = str(os.popen("top -n1 | awk 鈥?KiB/ {print $6}鈥?).readline().strip()).replace(鈥?鈥?/span>, 鈥樷€?/span> )
Ramused = int(Ramused)
Ramused = Ramused / 1000
print(鈥樷€?/span>)
print(鈥楻amused: %d 鈥?/span>%Ramused +鈥?Mb鈥?/span>)
def getDiskSpace():
p = os.popen("df -h /")
i = 0
while 1:
i = i +1
line = p.readline()
if i==2:
return(line.split()[1:5])
# Disk information
DISK_stats = getDiskSpace()
DISK_total = DISK_stats[0].replace(鈥楪鈥?/span>,鈥樷€?/span>)
DISK_used = DISK_stats[1].replace(鈥楪鈥?/span>, 鈥樷€?/span> )
DISK_perc = DISK_stats[3].replace(鈥?鈥?/span>, 鈥樷€?/span> )
print(鈥樷€?/span>)
print(鈥楧ISK_total: 鈥?/span>+str(DISK_total)+鈥?Gb鈥?/span>)
print(鈥楧ISK_used: 鈥?/span>+str(DISK_used)+鈥?Gb鈥?/span>)
print(鈥楧ISK_perc: 鈥?/span>+str(DISK_perc)+鈥?%鈥?/span>)
if __name__ == 鈥榑_main__鈥?/span>:
main()
涔熷彲浠ョ洿鎺ヤ笅杞借剼鏈枃浠讹細https://github.com/xinxingli/raspberry
鍦ㄦ湰鍦板皢浠g爜鍐欏叆info.py鏂囦欢锛岀劧鍚庢墽琛岋細
python info.py
灏卞彲浠ョ湅鍒版爲鑾撴淳杈撳嚭淇℃伅锛?/p>
gpu Temp: 34.70
cpu Temp: 34.17
load_1min: 0.20
load_5min: 0.25
Ramused: 264 Mb
DISK_total: 15 Gb
DISK_used: 3.9 Gb
DISK_perc: 29 %
鑾峰彇鏍戣帗娲惧綋鍓嶇姸鎬佸拰鏁版嵁锛堟俯搴︺€丆PU銆佸唴瀛樸€佺‖鐩橈級