樹(shù)莓派獲取CPU溫度,Python 腳本

參考文章
僅供個(gè)人學(xué)習(xí)參考

腳本代碼:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import commands
import os
import time

def main():
    # 查看GPU溫度
    #     gpu = float(gpu)
    #     print('gpu Temp: %.2f ' % gpu)

    # 查看CPU溫度
        file = open("/sys/class/thermal/thermal_zone0/temp")
        cpu = float(file.read()) / 1000
        file.close()
        print('')
        print('CPU 溫度: %2.2f' % cpu)

        load_1min = str(os.popen("top -n1 | awk '/load average:/ {print $12}'").readline().strip()).replace(',', '' )
        load_5min = str(os.popen("top -n1 | awk '/load average:/ {print $13}'").readline().strip()).replace(',', '' )
        load_1min=float(load_1min)
        load_5min=float(load_5min)
        # print('')
        # print('load_1min: %.2f'%load_1min)
        # print('load_5min: %.2f'%load_5min)

        Ramused = str(os.popen("top -n1 | awk '/KiB/ {print $6}'").readline().strip()).replace(',', '' )
        # Ramused = int(Ramused)
        # Ramused = Ramused / 1000
        # print('')
        # print('Ramused: '+Ramused+' KB')

        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('G','')
        DISK_used = DISK_stats[1].replace('G', '' )
        DISK_perc = DISK_stats[3].replace('%', '' )
        # print('')
        # print('DISK_total: '+str(DISK_total)+' Gb')
        # print('DISK_used: '+str(DISK_used)+' Gb')
        # print('DISK_perc: '+str(DISK_perc)+' %')
if __name__ == '__main__':
    while(True):
        main()
        #注意,此腳本是每10秒執(zhí)行一次,有需要自己修改
        time.sleep(10)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容